Module: L43::OpenObject::Behavior

Defined in:
lib/l43/open_object/behavior.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



7
8
9
10
# File 'lib/l43/open_object/behavior.rb', line 7

def ==(other)
  return false unless self.class === other
  other.to_h == to_h
end

#update(**kwds) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/l43/open_object/behavior.rb', line 12

def update(**kwds)
  if frozen?
    new_values = to_h.merge(**kwds)
    self.class.new(**new_values)
  else
    kwds.each do |k, v|
      instance_variable_set("@#{k}", v)
    end
    self
  end
end

#update_attribute(attribute, &blk) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
# File 'lib/l43/open_object/behavior.rb', line 24

def update_attribute(attribute, &blk)
  raise ArgumentError, "cannot update attribute #{attribute.inspect} without a block" unless blk
  update(attribute => blk.(to_h[attribute]))
end