Class: Configurer::Config

Inherits:
Module
  • Object
show all
Defined in:
lib/configurer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, &blk) ⇒ Object



9
# File 'lib/configurer.rb', line 9

def method_missing(sym, &blk); arr.first[sym] = blk; end

Instance Attribute Details

#arrObject

Returns the value of attribute arr.



8
9
10
# File 'lib/configurer.rb', line 8

def arr
  @arr
end

Instance Method Details

#[]=(sym, blk) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/configurer.rb', line 10

def []=(sym, blk)
  (arr = self.arr).last[sym] = blk
  define_method sym do
    frame = Module===self ? self : self.class
    blk   = arr.inject(nil){ |m, e| m || e[sym] }
    frame.instance_eval(&blk)
  end
end