Module: Virtus::ValueObject::InstanceMethods

Defined in:
lib/virtus/value_object.rb

Constant Summary collapse

FILTER_NONE =

the #get_attributes method accept a Proc object that will filter out an attribute when the block returns false. the ValueObject needs all the attributes, so we allow every attribute.

proc { true }

Instance Method Summary collapse

Instance Method Details

#cloneself Also known as: dup

ValueObjects are immutable and can’t be cloned

They always represent the same value

Examples:


value_object.clone === value_object # => true

Returns:

  • (self)


69
70
71
# File 'lib/virtus/value_object.rb', line 69

def clone
  self
end

#initialize(attributes = {}) ⇒ Object



50
51
52
# File 'lib/virtus/value_object.rb', line 50

def initialize(attributes = {})
  set_attributes(attributes)
end

#with(attribute_updates) ⇒ Object



54
55
56
# File 'lib/virtus/value_object.rb', line 54

def with(attribute_updates)
  self.class.new(get_attributes(&FILTER_NONE).merge(attribute_updates))
end