Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Ruby Programming Language

Can you make sense of this Array issue

In message <b034db400705261216x40b8da17xf2396c9013ac6@mail.gmail.com>, "Roland Mai" writes:

>I want to have an array, say 5x5 with all nils unless set to something else.
>However, when I set m[0][0] to 0 .. all 0 indices are set to zero.. Hmm..
>never asked for that to be the case.
>There's some funky stuff going on here.
>irb(main):001:0> n = 5
>=> 5
>irb(main):002:0> m = [[nil]*n]*n

Nothing odd here, you're making an array containing the SAME n-ary array
n times.


You might be interested in comparing:

Array.new(10, [])
Array.new(10) {[]}

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc