Class: Object

Inherits:
BasicObject
Includes:
InstanceExecHelper
Defined in:
lib/flt/support.rb

Overview

The math method of context needs instance_exec to pass parameters to the blocks evaluated with a modified self (pointing to a context object.) intance_exec is available in Ruby 1.9.1 and is also defined by ActiveRecord. Here we use Mauricio Fernández implementation if it is not available.

Defined Under Namespace

Modules: InstanceExecHelper

Instance Method Summary collapse

Instance Method Details

#instance_exec(*args, &block) ⇒ Object

!> method redefined; discarding old instance_exec



1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
# File 'lib/flt/support.rb', line 1425

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