Shot (Piotr Szotkowski)
1/29/2007 10:57:00 PM
Ball, Donald A Jr (Library):
> One question for the more advanced rubyists
Let a newbie answer. :) For a similar question, see my ‘Sane
#hash implementation?’ mail sent just a couple minutes ago.
> I use sets in one place, and tried to unit test the results, but
> Set.== didn't perform as I would have expected... for instance:
Set#== performs as advertised.
>> Set.new == Set.new
=> true
>> Set.new([1,2]) == Set.new([1,2])
=> true
> require 'set'
> s1 = Set.new
> s1 << {1=>2}
> s1 << {2=>3}
> s2 = Set.new
> s2 << {1=>2}
> s2 << {2=>3}
> s1 == s2
> is false.
> I thought that since Hash defines values-based ==,
> Set.== would use it, but it appears not.
Set#== docs say, ‘the equality of each couple of elements
is defined according to Object#eql?,’ and seem to be right:
>> Hash.new({1=>2}).eql? Hash.new({1=>2})
=> false
-- Shot
--
When you need a helpline for breakfast cereals, it's
time to start thinking about tearing down civilisation
and giving the ants a go. -- Chris King, asr