Class: ObjectHash
- Inherits:
-
Object
- Object
- ObjectHash
- Defined in:
- lib/object_hash.rb
Instance Method Summary collapse
-
#initialize(hash) ⇒ ObjectHash
constructor
A new instance of ObjectHash.
- #method_missing(name) ⇒ Object
- #respond_to_missing?(name, _include_private = false) ⇒ Boolean
Constructor Details
#initialize(hash) ⇒ ObjectHash
Returns a new instance of ObjectHash.
4 5 6 |
# File 'lib/object_hash.rb', line 4 def initialize(hash) @hash = hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
8 9 10 11 12 |
# File 'lib/object_hash.rb', line 8 def method_missing(name) value = find_hash_value(name) define_singleton_method(name) { value } value end |
Instance Method Details
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
14 15 16 17 18 19 |
# File 'lib/object_hash.rb', line 14 def respond_to_missing?(name, _include_private = false) return true if @hash.key?(name.to_sym) return true if @hash.key?(name.to_s) super end |