On Apr 28, 2004, at 1:04 AM, Robert Klemme wrote:

>
> "Mark Hubbart" <discord / mac.com> schrieb im Newsbeitrag
> news:56EB0554-986E-11D8-9038-000502FDD5CC / mac.com...
>> Hi,
>> I was messing around with recursive arrays and I came across this:
>>
>> mark@imac% cat hash.rb
>> a = []
>> a[0] = a
>> puts a.hash
>> mark@imac% ruby -v hash.rb
>> ruby 1.9.0 (2004-04-11) [powerpc-darwin]
>> hash.rb:3:in `hash': stack level too deep (SystemStackError)
>>          from hash.rb:3:in `hash'
>>          from hash.rb:3:in `hash'
>>          from hash.rb:3:in `hash'
>>          from hash.rb:3:in `hash'
>>          from hash.rb:3:in `hash'
>>          from hash.rb:3:in `hash'
>>          from hash.rb:3:in `hash'
>>          from hash.rb:3:in `hash'
>>           ... 44888 levels...
>>          from hash.rb:3:in `hash'
>>          from hash.rb:3:in `hash'
>>          from hash.rb:3:in `hash'
>>          from hash.rb:3
>>
>> .. looks like a bug?
>
> Hm, I'd say that for efficiency reasons loop detection in object 
> graphs of
> arrays is not done and thus it's a bug you'll have to live with.  After
> all, how often do you need self referencing containers?

Apparently if I *do* need self referencing arrays, I can't use #hash on 
them. Unless I redefine it so it works properly.

Anyway, I realized that the documentation for Array#hash is messed up. 
It claims (or at least implies) that #eql? uses #hash to compare 
values. I was assuming that a bug in #hash would make comparisons mess 
up. I was wrong :)

irb(main):047:0> [1].eql? [2,1]
=> false
irb(main):048:0> [1].hash == [2,1].hash
=> true

hashes are definitely not unique :)

--Mark