Forum: Ruby Strange bahaviour of "Set"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D5ed8e0a7843874dea90219264566b6b?d=identicon&s=25 Timo Hoepfner (thoepfner)
on 2005-12-12 09:10
(Received via mailing list)
Hi,

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"]]
     array_of_sets=array_of_arrays.map{|an_array| an_array.to_set}
     set_of_sets=array_of_sets.to_set
     contained_array=["a","b"]
     contained_set=contained_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))
   end
end

The third assertion fails. Is this intended behaviour?

Timo
F3b7109c91841c7106784d229418f5dd?d=identicon&s=25 Justin Collins (Guest)
on 2005-12-12 18:49
(Received via mailing list)
I believe include? checks for the specific Object ID for the set, not
the contents of the set.

-Justin
This topic is locked and can not be replied to.