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?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0