From: Tim Hunter Date: 2007-09-17T02:51:37+09:00 Subject: Re: bug with assignment? Mukund wrote: > The snippet illustrates my question. > > a={} > b={} > a["alpha"]=b["alpha"]=[] > a["alpha"]<<23 > b["alpha"]<<100 > puts a["alpha"] > puts b["alpha"] > > Here a["alpha"] and b["alpha"] both contain an array of [23,100]. > Why?? > > If I remove the multiple assignment, > a={} > b={} > a["alpha"]=[] > b["alpha"]=[] > a["alpha"]<<23 > b["alpha"]<<100 > puts a["alpha"] > puts b["alpha"] > > > a["alpha"] contains 23 and b["alpha"] contains 100 as I expected. > > Because, in the first case, both a["alpha"] and b["alpha"] refer to the same array. You simply have two different ways of referring to it. In the second case, the code constructs two different arrays. -- RMagick OS X Installer [http://rubyforge.org/projects/rmagick/] RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618] RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html]