Class: Irxrb::HashObject

Inherits:
Object show all
Defined in:
lib/irxrb/hash_object.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HashObject

Returns a new instance of HashObject.

Raises:

  • (ArgumentError)


3
4
5
6
# File 'lib/irxrb/hash_object.rb', line 3

def initialize(hash)
  raise ArgumentError, 'argument should be Hash' unless Hash === hash
  @hash = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(action, *args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/irxrb/hash_object.rb', line 8

def method_missing(action, *args)
  if @hash.has_key? action
    self.class.class_eval do
      define_method(action) do
        @hash[action]
      end
    end
    return __send__ action
  end
  super
end