Class: OpenStruct
Class Method Summary
collapse
Instance Method Summary
collapse
forward, forward_all, forward_self
Class Method Details
.to_proc ⇒ Object
11
12
13
14
15
|
# File 'lib/l43/open_struct.rb', line 11
def self.to_proc
-> hashy do
new hashy
end
end
|
Instance Method Details
#merge(other) ⇒ Object
17
18
19
|
# File 'lib/l43/open_struct.rb', line 17
def merge(other)
self.class.new(to_h.merge(other.to_h))
end
|
#merge_values(*keys, &merger) ⇒ Object
21
22
23
|
# File 'lib/l43/open_struct.rb', line 21
def merge_values(*keys, &merger)
self.class.new(to_h).update_values(*keys, &merger)
end
|
#update(hashy) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/l43/open_struct.rb', line 25
def update(hashy)
hashy.to_h.each do |k, v|
self[k] = v
end
self
end
|
#update_values(*keys, &updater) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/l43/open_struct.rb', line 32
def update_values(*keys, &updater)
keys.flatten.each do |key|
value = fetch(key) { raise KeyError, "must not update missing key: #{key.inspect}" }
value = updater.(value)
self[key] = value
end
self
end
|