solnic/virtus — Issue #40: special treatment for ValueObjects
Author: senny
Created: 2011-11-17 22:00:16+00:00
State: open

It would be nice if virtus had like a submodule for building ValueObjects. On top of my head this could look something like:

```ruby
class GeoLocation
include Virtus::ValueObject

attribute :latitude, Float
attribute :longitude, Float
end
```

The `Virtus::ValueObject` module would set some sane defaults for building ValueObjects like:

* They should be immutable so the setters are private
* They should be == when all the properties are equal
* We need to overwrite the #hash method since we defined a new == method
* the constructor should verify that all the properties have been set since the setters are not available. (not completely sure about that one. There might be cases where optional attributes are welcome)

```ruby
place = LatLng.new(:latitute => 40.73216945026674, :longitude => -74.091796875)
the_same_place = LatLng.new(:latitute => 40.73216945026674, :longitude => -74.091796875)
place == the_same_place # => true

hash = {palce => 1}
hash[the_same_palce] # => 1

place.latitude = -74.091796875 # => ERROR: Attempt to call private method
```