Class: Object

Inherits:
BasicObject
Includes:
InstanceExecHelper
Defined in:
lib/ext/object.rb

Overview

instance_exec for 1.8 Grabbed from Mauricio Fernandez (thanks!) For more information, see eigenclass.org/hiki.rb?instance_exec

Defined Under Namespace

Modules: InstanceExecHelper

Instance Method Summary collapse

Instance Method Details

#instance_exec(*args, &block) ⇒ Object

!> method redefined; discarding old instance_exec



7
8
9
10
11
12
13
14
15
16
# File 'lib/ext/object.rb', line 7

def instance_exec(*args, &block) # !> method redefined; discarding old instance_exec
  mname = "__instance_exec_#{Thread.current.object_id.abs}_#{object_id.abs}"
  InstanceExecHelper.module_eval{ define_method(mname, &block) }
  begin
    ret = send(mname, *args)
  ensure
    InstanceExecHelper.module_eval{ undef_method(mname) } rescue nil
  end
  ret
end