From: "headius (Charles Nutter)" Date: 2012-11-27T01:44:22+09:00 Subject: [ruby-core:50170] [ruby-trunk - Bug #7437] Array#delete(obj) should return obj when there is an object that is equal in the array Issue #7437 has been updated by headius (Charles Nutter). marcandre (Marc-Andre Lafortune) wrote: > Indeed, the documentation does not match the code and there is no test for this. > > It was clearly Matz' intention to return the (last) deleted element: https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/18527 > > This is the most helpful behavior anyways. > > I'll note that the documentation is clearly wrong in the second form too. > > Unless there is objection, I'll commit the following patch: Yes, it appears to have been an explicit behavioral change in the 1.9.1/1.8.7 timeframe that never got reflected in documentation. ---------------------------------------- Bug #7437: Array#delete(obj) should return obj when there is an object that is equal in the array https://bugs.ruby-lang.org/issues/7437#change-33969 Author: hasari (Hiro Asari) Status: Assigned Priority: Normal Assignee: marcandre (Marc-Andre Lafortune) Category: core Target version: 2.0.0 ruby -v: ruby 2.0.0dev (2012-11-25 trunk 37839) [x86_64-darwin12.2.1] 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 -- http://bugs.ruby-lang.org/