Module: Virtus::ValueObject::ClassMethods
- Defined in:
- lib/virtus/value_object.rb
Instance Method Summary collapse
-
#attribute(name, type, options = {}) ⇒ self
Define an attribute on the receiver.
-
#equalizer ⇒ Equalizer
Define and include a module that provides Value Object semantics.
Instance Method Details
#attribute(name, type, options = {}) ⇒ self
Define an attribute on the receiver
The Attribute will have private writer methods (eg., immutable instances)
and be used in equality/equivalence comparisons
119 120 121 122 |
# File 'lib/virtus/value_object.rb', line 119 def attribute(name, type, = {}) equalizer << name super name, type, .merge(:writer => :private) end |
#equalizer ⇒ Equalizer
Define and include a module that provides Value Object semantics
Included module will have #inspect, #eql?, #== and #hash methods whose definition is based on the keys argument
137 138 139 140 141 142 143 144 |
# File 'lib/virtus/value_object.rb', line 137 def equalizer @equalizer ||= begin equalizer = Virtus::Equalizer.new(name || inspect) include equalizer equalizer end end |