# Strange bahaviour of "Set"

**URL:** <https://www.ruby-forum.com/t/strange-bahaviour-of-set/50024>\
**Category:** Ruby\
**Created:** [December 12, 2005, 9:10am UTC](https://www.ruby-forum.com/t/strange-bahaviour-of-set/50024 "2005-12-12T09:10:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thoepfner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c37758/32.png) [@thoepfner](https://www.ruby-forum.com/u/thoepfner)\
**Post date:** [December 12, 2005, 9:10am UTC](https://www.ruby-forum.com/t/strange-bahaviour-of-set/50024/1 "2005-12-12T09:10:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thoepfner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c37758/32.png) [@thoepfner](https://www.ruby-forum.com/u/thoepfner)\
**Post date:** [December 12, 2005, 6:49pm UTC](https://www.ruby-forum.com/t/strange-bahaviour-of-set/50024/2 "2005-12-12T18:49:06Z")

</div>

I believe include? checks for the specific Object ID for the set, not  
the contents of the set.

-Justin
