From: Armin Armbruster Date: 2007-08-01T04:43:02+09:00 Subject: Re: Unexpected behavior with multidimensional arrays Dan Zwell wrote: > > The above does the same thing as ary = Array.new(3, []), but needs one > more line of code. > > What does everyone think? > > Dan Hmm, I guess my brain is still too much C-wired, but as Dan mentioned so are the brains of many others. Looks like a pretty frequent mistake to me. I can't think of a real world example where the current implementation of Array.new(3,[]) is usefull, but then I don't use arrays of Classes. It's like in C having an array of pointers that all point to the same address. To use Dan's example, if you continue with irb(main):005:0> ary[1] << "by" => ["hi", "by"] irb(main):006:0> ary => [["hi", "by"], ["hi", "by"], ["hi", "by"]] but obviously that's not what I intended to do (and we already discussed the solution how to do it right). Again, if anybody can come up with a simple and halfway applied example in which the current behavior is useful I would appreciate the enlightenment very much. Thanks, Armin -- Posted via http://www.ruby-forum.com/.