Class: Agnostic::Config

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

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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

def initialize
  @hash = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

def method_missing(method, *args, &block)
  if args.empty?
    @hash[method] ||= Config.new
  elsif block.nil?
    @hash[method] = args.size == 1 ? args.first : args
  else
    class << self; self end.class_eval do
      define_method(method){block.call(*args)}
    end
  end
end