Class: ConfigReader::MagicHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/config_reader/magic_hash.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



22
23
24
25
26
# File 'lib/config_reader/magic_hash.rb', line 22

def method_missing(key, *args, &block)
  has_key?(key) ?
    fetch(key) :
    super
end

Class Method Details

.convert_hash(hash) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/config_reader/magic_hash.rb', line 4

def self.convert_hash(hash)
  magic_hash = new

  hash.each_pair do |key, value|
    if value.is_a?(Hash)
      magic_hash[key.to_sym] = convert_hash(value)
    else
      magic_hash[key.to_sym] = value
    end
  end

  magic_hash
end

Instance Method Details

#[](key) ⇒ Object



18
19
20
# File 'lib/config_reader/magic_hash.rb', line 18

def [](key)
  fetch(key.to_sym)
end