Skip to content

Commit 2f915ca

Browse files
authored
Merge pull request #8436 from headius/enumerable_fixes
Pass Enumerable#uniq arguments properly
2 parents 01d88c3 + dfda4f2 commit 2f915ca

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

core/src/main/java/org/jruby/RubyEnumerable.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,19 @@ public static IRubyObject uniq(ThreadContext context, IRubyObject self, final Bl
21412141
if (block.isGiven()) {
21422142
callEach(context, each, self, Signature.OPTIONAL, new BlockCallback() {
21432143
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
2144-
return call(ctx, packEnumValues(ctx, largs), blk);
2144+
final IRubyObject obj; boolean ary = false;
2145+
switch (largs.length) {
2146+
case 0: obj = ctx.nil; break;
2147+
case 1: obj = largs[0]; break;
2148+
default: obj = RubyArray.newArrayMayCopy(ctx.runtime, largs); ary = true;
2149+
}
2150+
2151+
IRubyObject key = ary ? block.yieldArray(ctx, obj, null) : block.yield(ctx, obj);
2152+
2153+
if (hash.getEntry(key) == RubyHash.NO_ENTRY) {
2154+
hash.internalPut(key, obj);
2155+
}
2156+
return obj;
21452157
}
21462158
@Override
21472159
public IRubyObject call(ThreadContext ctx, IRubyObject obj, Block blk) {

0 commit comments

Comments
 (0)