Project

General

Profile

Actions

Bug #12684

closed

Delegator#eql? missing

Added by carsonreinke (Carson Reinke) over 7 years ago. Updated over 6 years ago.

Status:
Closed
Target version:
-
[ruby-core:76950]

Description

There is some strange behavior because Delegator is missing an alias of #eql? to #==

2.3.1 :001 > s = 'test'
 => "test" 
2.3.1 :002 > d = SimpleDelegator.new(s)
 => "test" 
2.3.1 :003 > d.eql?(d)
 => false 
2.3.1 :004 > d == d
 => true 
2.3.1 :005 > d.hash == d.hash
 => true

I understand that Delegator is a BasicObject and that does not define #eql? method, but this method is being used by Arrayr.

For example,

2.3.1 :001 > s = 'test'
 => "test" 
2.3.1 :002 > a = [SimpleDelegator.new(s), SimpleDelegator.new(s)]
 => ["test", "test"] 
2.3.1 :003 > a[0] == a[1]
 => true 
2.3.1 :004 > a.uniq()
 => ["test", "test"]
2.3.1 :005 > a[0].hash == a[1].hash
 => true

Kind of strange behavior, especially reading the documentation.

Now maybe, Array#uniq should be changed to use #== instead of #eql?

Updated by giginet (Kohki Miki) about 7 years ago

I fixed this issue and I added the specs.
Could you check it?

https://github.com/ruby/ruby/pull/1564
https://github.com/ruby/spec/pull/399

Updated by nobu (Nobuyoshi Nakada) about 7 years ago

  • Description updated (diff)
  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED

Seems fine.

Updated by ko1 (Koichi Sasada) almost 7 years ago

  • Assignee set to nobu (Nobuyoshi Nakada)

Updated by Eregon (Benoit Daloze) almost 7 years ago

@nobu (Nobuyoshi Nakada) Any update on this? I think your patch is OK.

Actions #5

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r59167.


Delegate to eql? [Fix GH-1564]

Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: WONTFIX

I think this is a spec change because of existence of the test in rubyspec about this behavior.
I will change WONTFIX for 2.4. Please tell us if there are any real world application suffered with this issue.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0