Forum: Ruby Strange bahaviour of "Set"

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Timo H. (Guest)
on 2005-12-12 10:10
(Received via mailing list)

I already mentioned this in another thread, but I think this is of
general interest. So sorry, if you read it twice.

While working on something involving the "Set" class of the Ruby
standard library, I came across the following:

require "set"
require "test/unit"

class TestSet < Test::Unit::TestCase

   def test_set
     array_of_arrays=[["a", "b"]]{|an_array| an_array.to_set}
     # OK
     assert_equal(true, array_of_arrays.include?(contained_array))
     # OK
     assert_equal(true, array_of_sets.include?(contained_set))
     # fails
     assert_equal(true, set_of_sets.include?(contained_set))

The third assertion fails. Is this intended behaviour?

Justin C. (Guest)
on 2005-12-12 19:49
(Received via mailing list)
I believe include? checks for the specific Object ID for the set, not
the contents of the set.

This topic is locked and can not be replied to.