module Virtus::ValueObject::InstanceMethods

Public Instance Methods

clone() click to toggle source

ValueObjects are immutable and can't be cloned

They always represent the same value

@example

value_object.clone === value_object # => true

@return [self]

@api public

# File lib/virtus/value_object.rb, line 60
def clone
  self
end
Also aliased as: dup
dup()
Alias for: clone
with(attribute_updates) click to toggle source

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

@example

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">

@return [Object]

@api public

# File lib/virtus/value_object.rb, line 77
def with(attribute_updates)
  self.class.new(attribute_set.get(self).merge(attribute_updates))
end