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
103 104 105 106 |
# File 'lib/virtus/value_object.rb', line 103 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
121 122 123 124 125 126 127 128 |
# File 'lib/virtus/value_object.rb', line 121 def equalizer @equalizer ||= begin equalizer = Virtus::Equalizer.new(name || inspect) include equalizer equalizer end end |