Class Object

  1. lib/spec/expectations/extensions/object.rb
  2. lib/spec/matchers/extensions/instance_exec.rb
  3. lib/spec/mocks/extensions/object.rb
  4. show all
Parent: Object

based on Bounded Spec InstanceExec (Mauricio Fernandez) eigenclass.org/hiki/bounded+space+instance_exec

Methods

public instance

  1. instance_exec

Classes and Modules

Module Object::InstanceExecHelper

Public instance methods

instance_exec (*args, &block)
[show source]
# File lib/spec/matchers/extensions/instance_exec.rb, line 9
    def instance_exec(*args, &block)
      begin
        orig_critical, Thread.critical = Thread.critical, true
        n = 0
        n += 1 while respond_to?(method_name="__instance_exec#{n}")
        InstanceExecHelper.module_eval{ define_method(method_name, &block) }
      ensure
        Thread.critical = orig_critical
      end
      begin
        return send(method_name, *args)
      ensure
        InstanceExecHelper.module_eval{ remove_method(method_name) } rescue nil
      end
    end