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)


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

def clone
  self
end

#initialize(attributes = {}) ⇒ Object



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

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

#with(attribute_updates) ⇒ Object



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

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