From: SpringFlowers AutumnMoon Date: 2007-09-18T02:03:40+09:00 Subject: Re: how to use tuple as hash key Stefano Crocco wrote: > > I think that ruby uses the content of the array, not its id: > > irb: 001> a=['a','b'] > ["a", "b"] > irb: 002> h = {a => 2} > {["a", "b"]=>2} > irb: 003> b = %w[a b] > ["a", "b"] > irb: 004> h[b] > 2 > irb: 005> a.object_id == b.object_id > false wow... this is deep... the reason I thought it uses the ID instead of the value is this: the code: ======================= h = {} for i in 1..2 for j in 1..2 h[[i,j]] = "ha" end end p h h2 = {} a = [0, 0] for i in 1..2 for j in 1..2 a[0] = i a[1] = j h2[a] = "ha" end end p h2 ======================= will produce: {[1, 2]=>"ha", [2, 1]=>"ha", [1, 1]=>"ha", [2, 2]=>"ha"} {[2, 2]=>"ha", [2, 2]=>"ha", [2, 2]=>"ha", [2, 2]=>"ha"} -- Posted via http://www.ruby-forum.com/.