Yukihiro Matsumoto writes: > Hi, > > In message "[ruby-talk:01092] Re: Infinite loop" > on 00/01/11, Clemens Hintze <clemens.hintze / alcatel.de> writes: > [...] > Here's two option to solve this. Which do you prefer? > > (a) like Array#inspect, Array#hash can use rb_protect_inspect() and > rb_inspecting_p() to detect cycles. > > (b) change the behavior of Array#hash not to traverse items > recursively. e.g. > > def hash > h = self.id > for item in self > h ^= item.id > end > h > end > > Both are real eacy to implement. I prefer latter. To be true, on the first glance I had prefer also the second one. But then I have imagined that this change would make impossible to write: a1 = ["hello", [1, 2, 3], "world"] a2 = [[1, 2, 3], "world", "hello"] a1.hash == a2.hash wouldn't it? I think this is a very nice property of Array! :-) As I do not know the rb_protect_inspect and rb_inspecting_p functions, I cannot say if the problem would also occur here. :-/ OTOH, your 2nd solution would retain the current property, iff the arrays would contains the same elements regardless of theirs order. What do you think? > > matz. \cle