Class: Irxrb::HashObject
Instance Method Summary collapse
-
#initialize(hash) ⇒ HashObject
constructor
A new instance of HashObject.
- #method_missing(action, *args) ⇒ Object
Constructor Details
#initialize(hash) ⇒ HashObject
Returns a new instance of HashObject.
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 |