Class: OpenStruct

Inherits:
Object
  • Object
show all
Extended by:
ExAequo::Base::Forwarder
Defined in:
lib/ex_aequo/base/open_struct.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ExAequo::Base::Forwarder

forward, forward_all

Class Method Details

.to_procObject



9
10
11
12
13
# File 'lib/ex_aequo/base/open_struct.rb', line 9

def self.to_proc
  -> hashy do
    new hashy
  end
end

Instance Method Details

#merge(other) ⇒ Object



15
16
17
# File 'lib/ex_aequo/base/open_struct.rb', line 15

def merge(other)
  self.class.new(to_h.merge(other.to_h))
end

#update(hashy) ⇒ Object



19
20
21
22
23
24
# File 'lib/ex_aequo/base/open_struct.rb', line 19

def update(hashy)
  hashy.to_h.each do |k, v|
    self[k] = v
  end
  self
end

#update_value(key, &blk) ⇒ Object



26
27
28
29
30
31
# File 'lib/ex_aequo/base/open_struct.rb', line 26

def update_value(key, &blk)
  self[key] = blk.(fetch(key))
  self
rescue KeyError
  raise KeyError, "key #{key} not found to update its value"
end