Creating Ruby Value Objects: The Idiomatic way
22-Mar-2025 61
If you want to read an article about this concept, I recommend Value Object by Martin Fowler. He explains this concept very well with examples and references. I invite you to read that article. It is not that long.
They are simple objects that have the following properties:
Comparable by type and value (that means two objects having the same values as attributes and being the same class will be equal)
Immutable (once set their attributes, they should not be allowed to be changed)
The concept is useful when you have to carry around multiple related values, and you need them together in most cases. When talking about Ruby and Ruby OOP, a value object is a simple immutable object that represents a concept in your domain and knows to respond to some simple messages like: what is the value of this property, what is your representation as a string, are you equal to this object in value and type and so on.
Creating Ruby Value Objects: The Idiomatic way #ruby #rubydeveloper #rubyonrails #Creating #Value #Objects: #Idiomatic https://rubyonrails.ba/link/creating-ruby-value-objects-the-idiomatic-way