Module: Dao::InstanceExec

Included in:
Presenter
Defined in:
lib/dao/instance_exec.rb

Constant Summary collapse

Code =
lambda do
  unless Object.new.respond_to?(:instance_exec)
    module InstanceExecHelper; end
    include InstanceExecHelper

    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
  end
end

Class Method Summary collapse

Class Method Details

.extend_object(other) ⇒ Object



32
33
34
35
# File 'lib/dao/instance_exec.rb', line 32

def InstanceExec.extend_object(other)
  other.instance_eval(&Code)
  super
end

.included(other) ⇒ Object



27
28
29
30
# File 'lib/dao/instance_exec.rb', line 27

def InstanceExec.included(other)
  other.module_eval(&Code)
  super
end