Class: Cfg
- Inherits:
-
Object
- Object
- Cfg
- Defined in:
- lib/cfg.rb
Instance Method Summary collapse
-
#initialize(x) ⇒ Cfg
constructor
A new instance of Cfg.
- #method_missing(m) ⇒ Object
Constructor Details
#initialize(x) ⇒ Cfg
Returns a new instance of Cfg.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/cfg.rb', line 4 def initialize(x) raise "First argument needs to be a string or a hash" unless [Hash, String].include? x.class if x.is_a? String x = YAML::load(File.read(x)) raise "YAML file must contain a single hash" unless x.is_a? Hash end @store = {} x.each do |k,v| @store[k.is_a?(Symbol) ? k : k.to_sym] = v end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m) ⇒ Object
16 17 18 19 |
# File 'lib/cfg.rb', line 16 def method_missing(m) if @store.has_key?(m); @store[m] else super(m); end end |