1 Oct 2003 01:19
Making == symmetric?
Nathan Weston <elbows <at> spamcop.net>
2003-09-30 23:19:27 GMT
2003-09-30 23:19:27 GMT
It has always bothered me that == is not symmetric in ruby:
a == b is shorthand for a.==(b), while b == a is shorthand for
b.==(a), and a and b might not agree on whether they are equal.
I have an idea as to how to fix this, and was thinking of posting an
RCR on rubygarden, but I thought I'd post here first and see if I've
missed any major problems.
First of all: yes, this issue does come up in real code.
Here's a quick example I ran into today:
require "delegate"
class Foo
end
class D < SimpleDelegator
def initialize(obj)
super(obj)
end
end
f = Foo.new
d = D.new(f)
d == f #evaluates to true
f == d #evaluates to false
I ran into a similar problem trying to implement perl6-style
junctions: you end up with any(1,2,3) == 1 being true, but 1 ==
(Continue reading)
RSS Feed