Project

General

Profile

Actions

Bug #7437

closed

Array#delete(obj) should return obj when there is an object that is equal in the array

Added by hasari (Hiro Asari) about 12 years ago. Updated about 12 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.0.0dev (2012-11-25 trunk 37839) [x86_64-darwin12.2.1]
Backport:
[ruby-core:50145]

Description

According to http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-delete, Array#delete(obj) should return "obj" when there are objects in the array that are "equal to obj" (internally, "==" is used, it seems).

Notice that the documentation does not state that the return value is an element of the array itself. However, 1.9.3 and trunk both return a member of the Array, rather than the argument.

This issue was raised in https://github.com/jruby/jruby/issues/411

#!/usr/bin/env ruby

class Foo
attr_reader :name, :age

def initialize name, age
@name = name
@age = age
end

def == other
other.name == name
end
end

foo1 = Foo.new "John Shahid", 27
foo2 = Foo.new "John Shahid", 28
array = [foo1]
temp = array.delete foo2 # => foo1, not foo2


Files

ruby-7437.patch (522 Bytes) ruby-7437.patch hasari (Hiro Asari), 11/26/2012 01:21 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0