Class: Object

Inherits:
BasicObject
Includes:
InstanceExecMethods
Defined in:
lib/buildr.rb,
lib/buildr/core/util.rb

Overview

:nodoc:

Defined Under Namespace

Modules: InstanceExecMethods

Constant Summary collapse

Scala =
Buildr::Scala

Instance Method Summary collapse

Instance Method Details

#instance_exec(*args, &block) ⇒ Object

Evaluate the block with the given arguments within the context of this object, so self is set to the method receiver.

From Mauricio’s eigenclass.org/hiki/bounded+space+instance_exec



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/buildr/core/util.rb', line 200

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