Class: MyStruct
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- MyStruct
show all
- Extended by:
- Forwarder, ClassMethods
- Defined in:
- lib/ex_aequo/my_struct.rb,
lib/ex_aequo/my_struct/class_methods.rb
Defined Under Namespace
Modules: ClassMethods
Classes: ImmutableError
Instance Method Summary
collapse
from_reduce
Instance Method Details
#[]= ⇒ Object
forward :fetch, to: :to_h
13
14
15
|
# File 'lib/ex_aequo/my_struct.rb', line 13
def[]=(*)
raise ImmutableError, "cannot change values with []= in immutable instance of #{self.class}"
end
|
#fetch(*args, &blk) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/ex_aequo/my_struct.rb', line 17
def fetch(*args, &blk)
to_h.fetch(*args, &blk)
rescue KeyError
raise KeyError,
"key #{args.first.inspect} not found in #{self} and no default given to #fetch"
end
|
#merge(with) ⇒ Object
24
25
26
|
# File 'lib/ex_aequo/my_struct.rb', line 24
def merge(with)
self.class.new(to_h.merge(with.to_h))
end
|
#slice(*args) ⇒ Object
28
29
30
|
# File 'lib/ex_aequo/my_struct.rb', line 28
def slice(*args)
self.class.new(to_h.slice(*args.flatten))
end
|