No.
$ irb -r set
1.9.3p125 :001 > set = ObjectSpace.each_object(Set).to_set
=> #<Set: {#<Set: {...}>}>
1.9.3p125 :002 > set.include?(set)
=> false
However, the Enumeration of all Enumerations does contain itself.
1.9.3p125 :001 > e = ObjectSpace.each_object(Enumerator) => #<Enumerator: ObjectSpace:each_object(Enumerator)> 1.9.3p125 :002 > e.include?(e) => true
Why this is so is left as an exercise to the reader.
After absolutely no research, I’m going to say that #to_set has something to do with it. Maybe #each_object returns a persistent reference to its results, and #to_set makes a copy, breaking the persistence. Otherwise #each_object returns an Enumerator and detects itself in the process.
April 3, 2012 at 5:07 pm
A guess off the top of my head: At the point when ObjectSpace.each_object is evaluated the Set object returned by #to_set does not exist, so it doesn’t include itself.
In the case of the Enumerator the actual process of finding all the objects in the system is lazily deferred until you start iterating over it. By that point the Enumerator object exists, and so it finds itself.
April 4, 2012 at 8:18 am
Isn’t this like saying if the universe contains itself?
April 5, 2012 at 4:53 pm