Class Index [+]

Quicksearch

RSpec::Matchers::Extensions::InstanceEvalWithArgs

Public Instance Methods

instance_eval_with_args(*args, &block) click to toggle source

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

  • uses singleton_class instead of global InstanceExecHelper module

  • this keeps it scoped to classes/modules that include this module

  • only necessary for ruby 1.8.6

    # File lib/rspec/matchers/extensions/instance_eval_with_args.rb, line 10
10:         def instance_eval_with_args(*args, &block)
11:           return instance_exec(*args, &block) if respond_to?(:instance_exec)
12: 
13:           # If there are no args and the block doesn't expect any, there's no
14:           # need to fake instance_exec with our hack below.
15:           # Notes:
16:           #   * lambda { }.arity # => -1
17:           #   * lambda { || }.arity # => 0
18:           #   * lambda { |*a| }.arity # -1
19:           return instance_eval(&block) if block.arity < 1 && args.empty?
20: 
21:           singleton_class = (class << self; self; end)
22:           begin
23:             orig_critical, Thread.critical = Thread.critical, true
24:             n = 0
25:             n += 1 while respond_to?(method_name="__instance_exec#{n}")
26:             singleton_class.module_eval{ define_method(method_name, &block) }
27:           ensure
28:             Thread.critical = orig_critical
29:           end
30:           begin
31:             return send(method_name, *args)
32:           ensure
33:             singleton_class.module_eval{ remove_method(method_name) } rescue nil
34:           end
35:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.