Module: Corn::Config::ClassMethods

Defined in:
lib/corn/config.rb

Instance Method Summary collapse

Instance Method Details

#config(hash = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/corn/config.rb', line 9

def config(hash={})
  @config ||= {}
  if hash.empty?
    @config
  else
    @config.merge!(hash)
    hash.each do |key, value|
      if self.respond_to?(key)
        next
      end
      q = !!value == value ? '?' : ''
      self.class_eval <<-RUBY, __FILE__, __LINE__
        def self.#{key}#{q}(*args)
          r = @config[:#{key}]
          r.is_a?(Proc) ? r.call(*args) : r
        end
      RUBY
    end
    @config
  end
end