【发布时间】:2010-03-27 15:45:09
【问题描述】:
下面是一些示例代码:
class Obj
attr :c, true
def == that
p '=='
that.c == self.c
end
def <=> that
p '<=>'
that.c <=> self.c
end
def equal? that
p 'equal?'
that.c.equal? self.c
end
def eql? that
p 'eql?'
that.c.eql? self.c
end
end
a = Obj.new
b = Obj.new
a.c = 1
b.c = 1
p [a] | [b]
它打印 2 个对象,但它应该打印 1 个对象。没有一个比较方法被调用。数组怎么样。|比较是否相等?
【问题讨论】:
标签: ruby