From: Hugh Sasse Date: 2005-09-16T01:13:20+09:00 Subject: Re: Sets, uniqueness not unique. On Fri, 16 Sep 2005, Robert Klemme wrote: > Hugh Sasse wrote: >> Hmm, that's interesting, but I don't get: >> >> code << "def hash() " << fields.map {|f| "self.#{f}.hash" }.join(" ^ >> ") << " end\n" >> >> Shouldn't hash return a Fixnum? > > Definitely! > [...] >> The function above appears to return a string with numbers separated >> by " ^ ". > > Nope. The join appears during code generation and not during evaluation > of the method. You can easily verify this by printing code after it's > completed. :-) Oh, then it's exclusive or. I'm clearly being as sharp as a sponge today. While my brain is behaving like cottage cheese, it's probably not the time to ask how one might guarantee that you don't stomp on the hashes of other ojects in the system. If you have an even number of elements, all the same Fixnum, like [1,1,1,1] then they would hash to 0, as would [2,2], I "think". irb(main):004:0> [1,1].inject(0) { |a,b| a ^= b.hash} => 0 irb(main):005:0> [2,1,1,2].inject(0) { |a,b| a ^= b.hash} => 0 irb(main):006:0> > > Kind regards > > robert > Hugh