Class: AutoPilot::Config
- Inherits:
-
Object
- Object
- AutoPilot::Config
- Defined in:
- lib/auto_pilot/configure.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(data = {}) ⇒ Config
constructor
A new instance of Config.
-
#method_missing(sym, *args) ⇒ Object
def to_hash @data end.
- #update(data) ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ Config
Returns a new instance of Config.
15 16 17 18 |
# File 'lib/auto_pilot/configure.rb', line 15 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
def to_hash
@data
end
42 43 44 45 46 47 48 |
# File 'lib/auto_pilot/configure.rb', line 42 def method_missing(sym, *args) if sym.to_s =~ /(.+)=$/ self[Regexp.last_match(1)] = args.first else self[sym] end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
13 14 15 |
# File 'lib/auto_pilot/configure.rb', line 13 def data @data end |
Instance Method Details
#[](key) ⇒ Object
26 27 28 |
# File 'lib/auto_pilot/configure.rb', line 26 def [](key) @data[key.to_sym] end |
#[]=(key, value) ⇒ Object
30 31 32 |
# File 'lib/auto_pilot/configure.rb', line 30 def []=(key, value) @data[key.to_sym] = value end |
#update(data) ⇒ Object
20 21 22 23 24 |
# File 'lib/auto_pilot/configure.rb', line 20 def update(data) data.each do |key, value| self[key.to_sym] = value end end |