Class Index [+]

Quicksearch

RSpec::Core::Extensions::InstanceEvalWithArgs

@private

Public Instance Methods

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

@private

Used internally to support `instance_exec` in Ruby 1.8.6.

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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.