Class: Configr::Hash

Inherits:
Hash
  • Object
show all
Includes:
HashExtensions
Defined in:
lib/configr/hash.rb

Instance Method Summary collapse

Methods included from HashExtensions

#recursive_symbolize_keys!, #symbolize_keys!

Constructor Details

#initialize(hash) ⇒ Hash

Returns a new instance of Hash.



23
24
25
# File 'lib/configr/hash.rb', line 23

def initialize(hash)
  hash ? hash.each_pair { |key, val| self.delete(key.to_s); self[key] = val } : self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



40
41
42
# File 'lib/configr/hash.rb', line 40

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

Instance Method Details

#normalize!Object



27
28
29
30
31
32
33
# File 'lib/configr/hash.rb', line 27

def normalize!
  recursive_symbolize_keys!
  
  each_pair do |key, val|
    self[key] = Hash.new(val) if val.is_a?(::Hash)
  end
end

#recursive_normalize!Object



35
36
37
38
# File 'lib/configr/hash.rb', line 35

def recursive_normalize!
  normalize!
  values.select { |val| val.is_a?(::Hash) }.each { |hash| hash.recursive_normalize! }
end