From fe138bf2081e312abf4a5785be6ee559e4d6df01 Mon Sep 17 00:00:00 2001 From: Hiro Asari Date: Sun, 25 Nov 2012 22:14:07 -0500 Subject: [PATCH] Array#delete should delete the first object *inside* the array, not the one that is given as the argument to it, even when the objects are equal via '=='. This fixes #411. --- src/org/jruby/RubyArray.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/org/jruby/RubyArray.java b/src/org/jruby/RubyArray.java index b34e08e6f3c..fea15dc3837 100644 --- a/src/org/jruby/RubyArray.java +++ b/src/org/jruby/RubyArray.java @@ -2459,13 +2459,17 @@ public IRubyObject keep_if(ThreadContext context, Block block) { @JRubyMethod(required = 1) public IRubyObject delete(ThreadContext context, IRubyObject item, Block block) { int i2 = 0; + IRubyObject value = item; Ruby runtime = context.runtime; for (int i1 = 0; i1 < realLength; i1++) { // Do not coarsen the "safe" check, since it will misinterpret AIOOBE from equalInternal // See JRUBY-5434 IRubyObject e = safeArrayRef(values, begin + i1); - if (equalInternal(context, e, item)) continue; + if (equalInternal(context, e, item)) { + value = e; + continue; + } if (i1 != i2) store(i2, e); i2++; } @@ -2492,7 +2496,7 @@ public IRubyObject delete(ThreadContext context, IRubyObject item, Block block) concurrentModification(); } - return item; + return value; } /** rb_ary_delete_at