Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: baf794d0f6c2
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a246ed6e32f9
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Dec 26, 2015

  1. Allow #instance_eval to evaluate procs originated from methods

    Fixes #3539
    ahmadsherif authored and Yorick Peterse committed Dec 26, 2015
    Copy the full SHA
    f0d2089 View commit details
  2. Copy the full SHA
    a246ed6 View commit details
Showing with 12 additions and 0 deletions.
  1. +3 −0 kernel/common/eval.rb
  2. +9 −0 spec/ruby/core/kernel/instance_eval_spec.rb
3 changes: 3 additions & 0 deletions kernel/common/eval.rb
Original file line number Diff line number Diff line change
@@ -31,6 +31,9 @@ def instance_eval(string=nil, filename="(eval)", line=1, &prc)
if string
raise ::ArgumentError, 'cannot pass both a block and a string to evaluate'
end

return prc.ruby_method.call(self) if prc.ruby_method

# Return a copy of the BlockEnvironment with the receiver set to self
env = prc.block

9 changes: 9 additions & 0 deletions spec/ruby/core/kernel/instance_eval_spec.rb
Original file line number Diff line number Diff line change
@@ -138,4 +138,13 @@ class B; end
(1 << 64).instance_eval { def foo; end }
end.should raise_error(TypeError)
end

it "evaluates procs originating from methods" do
def meth(arg); arg; end

m = method(:meth)
obj = Object.new

obj.instance_eval(&m).should == obj
end
end