Class: Object

Inherits:
BasicObject
Includes:
InstanceExecHelper
Defined in:
lib/rjr/core_ext.rb

Overview

Defined Under Namespace

Modules: InstanceExecHelper

Instance Method Summary collapse

Instance Method Details

#instance_exec(*args, &block) ⇒ Object

Execute the specified block in the scope of the local object

Parameters:

  • args (Array)

    array of args to be passed to block

  • block (Callable)

    callable object to bind and invoke in the local namespace



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rjr/core_ext.rb', line 31

def instance_exec(*args, &block)
  begin
    old_critical, Thread.critical = Thread.critical, true
    n = 0
    n += 1 while respond_to?(mname="__instance_exec#{n}")
    InstanceExecHelper.module_eval{ define_method(mname, &block) }
  ensure
    Thread.critical = old_critical
  end
  begin
    ret = send(mname, *args)
  ensure
    InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
  end
  ret
end