Class: ApplicationConfig::DataStructures::NestedHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/application_config/data_structures/nested_hash.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ NestedHash

Returns a new instance of NestedHash.



6
7
8
# File 'lib/application_config/data_structures/nested_hash.rb', line 6

def initialize(hash = {})
  self.update(hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



17
18
19
# File 'lib/application_config/data_structures/nested_hash.rb', line 17

def method_missing(method_name)
  self[method_name.to_s]
end

Instance Method Details

#[](key) ⇒ Object



10
11
12
13
14
15
# File 'lib/application_config/data_structures/nested_hash.rb', line 10

def [](key)
  value = fetch(key, nil)
  return ApplicationConfig::DataStructures::AlwaysNullNode.new unless value
  return ApplicationConfig::DataStructures::ValueNode.new(value) unless value.kind_of?(Hash)
  return ApplicationConfig::DataStructures::NestedHash.new(value)
end