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: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ba467df89872
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a4a7172c841b
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 10, 2016

  1. Copy the full SHA
    423df80 View commit details
  2. Copy the full SHA
    a4a7172 View commit details
Showing with 14 additions and 1 deletion.
  1. +2 −1 core/src/main/ruby/jruby/kernel/hash.rb
  2. +12 −0 spec/ruby/core/hash/to_proc_spec.rb
3 changes: 2 additions & 1 deletion core/src/main/ruby/jruby/kernel/hash.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Hash
def to_proc
->(key) {self[key]}
hash_self = self
->(key) {hash_self[key]}
end
end
12 changes: 12 additions & 0 deletions spec/ruby/core/hash/to_proc_spec.rb
Original file line number Diff line number Diff line change
@@ -26,6 +26,18 @@
end
end

context "passed as the block for instance_exec" do
it "always retrieves the original hash's values" do
hash = {foo: 1, bar: 2}
proc = hash.to_proc

hash.instance_exec(:foo, &proc).should == 1

hash2 = {quux: 1}
hash2.instance_exec(:foo, &proc).should == 1
end
end

context "with no stored key" do
it "returns nil" do
@proc.call(@unstored).should be_nil