[ruby-core:94750] [Ruby master Bug#6408] DelegateClass#eql? and <=> don't work as expected

From: merch-redmine@...
Date: 2019-09-03 01:05:37 UTC
List: ruby-core #94750
Issue #6408 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Assigned to Closed

Delegate now handles `eql?` after changes from #12684.  However, it always returns true if the object is the same:

```ruby
nan = 0/0.0
nan.eql? nan # false
s = SimpleDelegator.new(nan)
s.eql? s # true
```

I'm not sure it is worth it to add explicit support for making it so `eql?` can return false if the target doesn't consider itself to be equal to itself.

As mame mentioned, `<=>` is for sorting, and it probably isn't helpful to have a sorting method that handles multiple copies of the same delegate object in an array, but not multiple different delegates of the same target in an array.

Considering the `eql?` issue has been fixed, which was the underlying cause of the Rails issue that caused this ticket to be filed, I think this is safe to close.  If I'm wrong, please reopen.

----------------------------------------
Bug #6408: DelegateClass#eql? and <=> don't work as expected
https://bugs.ruby-lang.org/issues/6408#change-81368

* Author: tenderlovemaking (Aaron Patterson)
* Status: Closed
* Priority: Normal
* Assignee: tenderlovemaking (Aaron Patterson)
* Target version: 
* ruby -v: ruby 2.0.0dev (2012-05-06 trunk 35548) [x86_64-darwin11.3.0]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
It seems these two methods aren't delegating to the delegate object when compared against itself.

I've attached a patch with tests and a fix.  It seems nobody is the maintainer for delegate.rb (according to the wiki), so if nobody objects, I will apply this patch.

---Files--------------------------------
fix.patch (1.45 KB)
noname (500 Bytes)
noname (500 Bytes)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next