Skip to content

Commit

Permalink
Showing 2 changed files with 35 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -1317,7 +1317,7 @@ public RubyHash eachCommon(final ThreadContext context, final Block block) {
iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
block.yieldSpecific(context, key, value);
block.yieldArray(context, context.runtime.newArray(key, value), null);
}
});
} else {
@@ -1326,7 +1326,7 @@ public void visit(IRubyObject key, IRubyObject value) {
iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
block.yield(context, RubyArray.newArray(runtime, key, value));
block.yieldArray(context, RubyArray.newArray(runtime, key, value), null);
}
});
}
@@ -1425,7 +1425,7 @@ public boolean keep_ifCommon(final ThreadContext context, final Block block) {
iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
if (!block.yieldSpecific(context, key, value).isTrue()) {
if (!block.yieldArray(context, context.runtime.newArray(key, value), null).isTrue()) {
modified[0] = true;
remove(key);
}
@@ -1878,7 +1878,7 @@ private IRubyObject any_p_i(ThreadContext context, Block block) {
try {
for (RubyHashEntry entry = head.nextAdded; entry != head; entry = entry.nextAdded) {
IRubyObject newAssoc = RubyArray.newArray(context.runtime, entry.key, entry.value);
if (block.yield(context, newAssoc).isTrue())
if (block.yieldArray(context, newAssoc, null).isTrue())
return context.getRuntime().getTrue();
}
return context.getRuntime().getFalse();
@@ -1891,7 +1891,7 @@ private IRubyObject any_p_i_fast(ThreadContext context, Block block) {
iteratorEntry();
try {
for (RubyHashEntry entry = head.nextAdded; entry != head; entry = entry.nextAdded) {
if (block.yieldSpecific(context, entry.key, entry.value).isTrue())
if (block.yieldArray(context, context.runtime.newArray(entry.key, entry.value), null).isTrue())
return context.getRuntime().getTrue();
}
return context.getRuntime().getFalse();
30 changes: 30 additions & 0 deletions spec/regression/GH-3137_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'rspec'

describe "A bunch of hash methods" do
let(:hash) { {a: :b} }

it "can handle standard arities for any?" do
hash.any? { |k| expect(k).to eq(:a) }
hash.any? { |k,v| expect(k).to eq(:a); expect(v).to eq(:b) }
end

it "can handle standard arities for delete_if" do
hash.delete_if { |k| expect(k).to eq(:a) }
hash.delete_if { |k,v| expect(k).to eq(:a); expect(v).to eq(:b) }
end

it "can handle standard arities for each" do
hash.each { |k| expect(k).to eq(:a) }
hash.each { |k,v| expect(k).to eq(:a); expect(v).to eq(:b) }
end

it "can handle standard arities for select" do
hash.select { |k| expect(k).to eq(:a) }
hash.select { |k,v| expect(k).to eq(:a); expect(v).to eq(:b) }
end

it "can handle standard arities for select!" do
hash.select! { |k| expect(k).to eq(:a) }
hash.select! { |k,v| expect(k).to eq(:a); expect(v).to eq(:b) }
end
end

0 comments on commit 303a128

Please sign in to comment.