Class: ObjectHash

Inherits:
Object
  • Object
show all
Defined in:
lib/object_hash.rb

Instance Method Summary collapse

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

Returns:

  • (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