Class: ShootingStar::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Config



3
4
5
6
7
8
# File 'lib/shooting_star/config.rb', line 3

def initialize(hash)
  @hash = hash.keys.inject({}) do |new_hash, key|
    new_hash[key.to_s] = hash[key]
    new_hash
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



14
15
16
17
# File 'lib/shooting_star/config.rb', line 14

def method_missing(method, *arg, &block)
  value = @hash[method.to_s]
  value.is_a?(Hash) ? Config.new(value) : value
end

Instance Method Details

#merge!(hash) ⇒ Object



10
11
12
# File 'lib/shooting_star/config.rb', line 10

def merge!(hash)
  hash.keys.each{|key| @hash[key.to_s] = hash[key]}; self
end