Class: Hadley::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Config

Returns a new instance of Config.



3
4
5
# File 'lib/hadley/config.rb', line 3

def initialize(config={})
  @config = config
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



7
8
9
10
11
12
13
14
15
# File 'lib/hadley/config.rb', line 7

def method_missing(name, *args, &block)
  if block_given?
    proc(name, &block)
  elsif name =~ /(.+)=$/
    set($1, *args, &block)
  else
    get(name, &block)
  end
end

Instance Method Details

#get(name, &block) ⇒ Object



25
26
27
# File 'lib/hadley/config.rb', line 25

def get(name, &block)
  @config[name.to_sym]
end

#proc(name, &block) ⇒ Object



17
18
19
# File 'lib/hadley/config.rb', line 17

def proc(name, &block)
  @config[name.to_sym] = block
end

#set(name, *args) ⇒ Object



21
22
23
# File 'lib/hadley/config.rb', line 21

def set(name, *args)
  @config[name.to_sym] = args.size == 1 ? args.first : args
end