Class: DeepStruct::Hash

Inherits:
Hash
  • Object
show all
Defined in:
lib/deep_struct/hash.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Hash

Returns a new instance of Hash.



3
4
5
6
7
# File 'lib/deep_struct/hash.rb', line 3

def initialize(hash)
  hash.each do |k, v|
    self[k.to_sym] = v
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *args, &block) ⇒ Object



13
14
15
# File 'lib/deep_struct/hash.rb', line 13

def method_missing(key, *args, &block)
  self[key]
end

Instance Method Details

#[](key) ⇒ Object



9
10
11
# File 'lib/deep_struct/hash.rb', line 9

def [](key)
  DeepStruct.convert_element_if_possible(super)
end

#responds_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/deep_struct/hash.rb', line 17

def responds_to?(method)
  self[method]
end