Module: CarryOut::Cloaker

Included in:
Plan::NodeContext, PlanBuilder
Defined in:
lib/carry_out/cloaker.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



24
25
26
27
28
29
30
# File 'lib/carry_out/cloaker.rb', line 24

def method_missing(method, *args, &block)
  if @previous_context
    @previous_context.send(method, *args, &block)
  else
    super
  end
end

Instance Method Details

#cloaker(binding = nil, &b) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/carry_out/cloaker.rb', line 6

def cloaker(binding = nil, &b)
  meth = self.class.class_eval do
    define_method :cloaker_, &b
    meth = instance_method :cloaker_
    remove_method :cloaker_
    meth
  end
  
  with_previous_context(binding || b.binding) { meth.bind(self).call }
end

#with_previous_context(binding, &block) ⇒ Object



17
18
19
20
21
22
# File 'lib/carry_out/cloaker.rb', line 17

def with_previous_context(binding, &block)
  @previous_context = binding.eval('self')
  result = block.call
  @previous_context = nil
  result
end