summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--array.c6
-rw-r--r--test/ruby/test_array.rb8
2 files changed, 11 insertions, 3 deletions
diff --git a/array.c b/array.c
index d90f08b7d1..2454b99d76 100644
--- a/array.c
+++ b/array.c
@@ -2735,12 +2735,12 @@ ary_resize_smaller(VALUE ary, long len)
/*
* call-seq:
- * ary.delete(obj) -> obj or nil
- * ary.delete(obj) { block } -> obj or nil
+ * ary.delete(obj) -> item or nil
+ * ary.delete(obj) { block } -> item or result of block
*
* Deletes all items from +self+ that are equal to +obj+.
*
- * If any items are found, returns +obj+, otherwise +nil+ is returned instead.
+ * Returns the last deleted item, or +nil+ if no matching item is found.
*
* If the optional code block is given, the result of the block is returned if
* the item is not found. (To remove +nil+ elements and get an informative
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 6c447c2626..6c7f920d79 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -598,6 +598,14 @@ class TestArray < Test::Unit::TestCase
a = @cls[*('cab'..'cat').to_a]
assert_equal(99, a.delete('cup') { 99 } )
assert_equal(@cls[*('cab'..'cat').to_a], a)
+
+ o = Object.new
+ def o.==(other); true; end
+ o2 = Object.new
+ def o2.==(other); true; end
+ a = @cls[1, o, o2, 2]
+ assert_equal(o2, a.delete(42))
+ assert_equal([1, 2], a)
end
def test_delete_at