Class: Qinium::Configurable

Inherits:
Hash
  • Object
show all
Defined in:
lib/qinium/configurable.rb

Direct Known Subclasses

Config

Instance Method Summary collapse

Constructor Details

#initialize(defaults = {}) ⇒ Configurable

Returns a new instance of Configurable.



3
4
5
6
7
# File 'lib/qinium/configurable.rb', line 3

def initialize(defaults = {})
  defaults.each_pair do |k, v|
    self[k.to_sym] = v.is_a?(Hash) ? Configurable.new(v) : v
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/qinium/configurable.rb', line 13

def method_missing(method, *args)
  if method.to_s.end_with?("=")
    self[method.to_s[0..-2].to_sym] = args[0]
  else
    fetch(method.to_sym)
  end
end

Instance Method Details

#[]=(k, v) ⇒ Object



9
10
11
# File 'lib/qinium/configurable.rb', line 9

def []=(k, v)
  super(k.to_sym, v)
end

#respond_to_missing?(method) ⇒ Boolean

Returns:



21
22
23
24
# File 'lib/qinium/configurable.rb', line 21

def respond_to_missing?(method)
  key = method.to_s.end_with?("=") ? method.to_s[0..-2].to_sym : method
  key?(key)
end