# Re: Counting Toothpicks (#111)

I have a fairly verbose submission for this quiz. It’s probably quite
slow compared to others, but at least I can follow my own code One
question for the more advanced rubyists - 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:

require ‘set’
s1 = Set.new
s1 << {1=>2}
s1 << {2=>3}
s2 = Set.new
s2 << {1=>2}
s2 << {2=>3}
s1 == s2

is false. Presumably this is due to reference v.s. values equality, but
I thought that since Hash defines values-based ==, Set.== would use it,
but it appears not. This is somewhat surprising, I’ll warrant.

Oh, and what’s the preferred submission method - attachment, inclusion,
or pastie?

• donald

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.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

On Jan 29, 2007, at 4:16 PM, Ball, Donald A Jr (Library) wrote:

Oh, and what’s the preferred submission method - attachment,
inclusion,
or pastie?

I personally think inline code is the best for the purposes of the
archives.

I’ve enjoyed the habit some are getting into by providing the pastie
link as an option though. With that, syntax highlighting is only a