Class: AngryMob::Target::Defaults

Inherits:
Object
  • Object
show all
Defined in:
lib/angry_mob/target/defaults.rb

Instance Method Summary collapse

Constructor Details

#initializeDefaults

Returns a new instance of Defaults.



4
5
6
# File 'lib/angry_mob/target/defaults.rb', line 4

def initialize
  @contexts = Hash.new {|h,k| h[k] = []}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



13
14
15
16
17
18
19
20
# File 'lib/angry_mob/target/defaults.rb', line 13

def method_missing(method, *args, &blk)
  @contexts[method] << args.first

  if block_given?
    yield
    @contexts[method].pop
  end
end

Instance Method Details

#defaults_for(name) ⇒ Object



8
9
10
11
# File 'lib/angry_mob/target/defaults.rb', line 8

def defaults_for(name)
  @contexts[name].last || {}
  # TODO -> merge under some circumstances
end