Class: Ford::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/ford/config.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(data = {}) ⇒ Config
Returns a new instance of Config.
9
10
11
12
|
# File 'lib/ford/config.rb', line 9
def initialize(data={})
@data = {}
update!(data)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/ford/config.rb', line 32
def method_missing(sym, *args)
if sym.to_s =~ /(.+)=$/
self[$1] = args.first
else
self[sym]
end
end
|
Instance Method Details
#[](key) ⇒ Object
20
21
22
|
# File 'lib/ford/config.rb', line 20
def [](key)
@data[key.to_sym]
end
|
#[]=(key, value) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/ford/config.rb', line 24
def []=(key, value)
if value.class == Hash
@data[key.to_sym] = Config.new(value)
else
@data[key.to_sym] = value
end
end
|
#update!(data) ⇒ Object
14
15
16
17
18
|
# File 'lib/ford/config.rb', line 14
def update!(data)
data.each do |key, value|
self[key] = value
end
end
|