Class: HashContext

Inherits:
Object show all
Defined in:
lib/open_classes/hash/gte_gte.rb

Overview

HashContext

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#receiverObject (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_hObject



27
28
29
# File 'lib/open_classes/hash/gte_gte.rb', line 27

def to_h
  @receiver
end