Module: Virtus::ValueObject::InstanceMethods

Defined in:
lib/virtus/value_object.rb

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)


60
61
62
# File 'lib/virtus/value_object.rb', line 60

def clone
  self
end

#with(attribute_updates) ⇒ Object

Create a new ValueObject by combining the passed attribute hash with the instances attributes.

Examples:


number = PhoneNumber.new(kind: "mobile", number: "123-456-78-90")
number.with(number: "987-654-32-10")
# => #<PhoneNumber kind="mobile" number="987-654-32-10">

Returns:

  • (Object)


77
78
79
# File 'lib/virtus/value_object.rb', line 77

def with(attribute_updates)
  self.class.new(attribute_set.get(self).merge(attribute_updates))
end