Class: HashContext
Overview
HashContext
Instance Attribute Summary collapse
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
Instance Method Summary collapse
-
#initialize(receiver) ⇒ HashContext
constructor
A new instance of HashContext.
- #method_missing(method_name, *args, &block) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(receiver) ⇒ HashContext
Returns a new instance of HashContext.
6 7 8 |
# File 'lib/open_classes/hash/gte_gte.rb', line 6 def initialize(receiver) @receiver = receiver end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/open_classes/hash/gte_gte.rb', line 10 def method_missing(method_name, *args , &block) result = nil if args.size > 0 receiver.reduce({}) do |ret, (key, value)| value = value.send method_name, *args ret[key] = value ret end else receiver.reduce({}) do |ret, (key , value)| value = value.send method_name ret[key] = value ret end end end |
Instance Attribute Details
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
5 6 7 |
# File 'lib/open_classes/hash/gte_gte.rb', line 5 def receiver @receiver end |
Instance Method Details
#to_h ⇒ Object
27 28 29 |
# File 'lib/open_classes/hash/gte_gte.rb', line 27 def to_h @receiver end |