Module: InstanceExecModule

Includes:
InstanceExecMethods
Included in:
Postful::Order
Defined in:
lib/postful/instance_exec_module.rb

Overview

:nodoc:

Defined Under Namespace

Modules: InstanceExecMethods

Instance Method Summary collapse

Instance Method Details

#instance_exec(*args, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/postful/instance_exec_module.rb', line 8

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