From: Smgspices@... Date: 2006-11-16T05:47:34+09:00 Subject: Fwd: Multidimensional Arrays --part1_327.10162e6d.328cd6dd_boundary Content-Type: multipart/alternative; boundary="-----------------------------1163623645" -------------------------------1163623645 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit -------------------------------1163623645 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable
 
-------------------------------1163623645-- --part1_327.10162e6d.328cd6dd_boundary Content-Type: message/rfc822 Content-Disposition: inline Return-path: From: Smgspices@aol.com Full-name: Smgspices Message-ID: Date: Wed, 15 Nov 2006 12:24:44 EST Subject: Multidimensional Arrays To: ruby-talk-ctl@ruby-lang.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-----------------------------1163611484" X-Mailer: 9.0 Security Edition for Windows sub 5326 -------------------------------1163611484 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit I thought the answer about how to create multidimensional arrays as presented here was very interesting, "create an array of arrays." A funny thing happened on the way to the store. I fired up FreeRIDE and entered, "chessboard = Array.new(8, Array.new(8, " ")) like so: irb(main):009:0> chessboard=Array.new(8,Array.new(8," ")) => [[" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " ", " "]] This was exactly as I expected. Then I tried putting a pawn on the board: irb(main):010:0> chessboard[3][3]="Pawn" => "Pawn" Then I looked at the board: irb(main):011:0> chessboard => [[" ", " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " ", " "]] You have got to be kidding. The pawn shows up eight times. Not at all what I expected nor what I wanted. No matter how I tried, I could not make just one entry in the array of arrays. It appears to me that you have to roll your own when using Ruby. Either that or I've misunderstood or made an error in trying to use the information I have gained. I am very new to this "Ruby" thing and OO in general but it appears to me that we've got to create a class that contains the required definitions (methods, variables, etc.). Charles Gray -- Phoenix, AZ (tcykgreis on skype and google-talk) -------------------------------1163611484 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable
I thought the answer about how to create multidimensional arrays as=20 presented here was very interesting, "create an array of arrays." A funny th= ing=20 happened on the way to the store.
I fired up FreeRIDE and entered, "chessboard =3D Array.new(8, Array.new= (8, "=20 ")) like so:
 
irb(main):009:0> chessboard=3DArray.new(8,Array.new(8," "))
=3D&g= t; [["=20 ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " ", "= "],=20 [" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " "= , "=20 "], [" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ",= "=20 ", " "], [" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ",= "=20 ", " ", " "]]
 
This was exactly as I expected. Then I tried putting a pawn on the=20 board:

irb(main):010:0> chessboard[3][3]=3D"Pawn"
=3D> "Pawn"
 
Then I looked at the board:

irb(main):011:0> chessboard
=3D> [[" ", " ", " ", "Pawn",=20= " ", "=20 ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ",=20 "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " ", " "], ["= ",=20 " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " "= , "=20 "], [" ", " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " "= , "=20 ", " ", " "]]
 
You have got to be kidding. The pawn shows up eight times. Not at all w= hat=20 I expected nor what I wanted. No matter how I tried, I could not make just o= ne=20 entry in the array of arrays. It appears to me that you have to roll yo= ur=20 own when using Ruby. Either that or I've misunderstood or made an error in=20 trying to use the information I have gained. 
 
I am very new to this "Ruby" thing and OO in general but it appears to=20= me=20 that we've got to create a class that contains the required definitions=20 (methods, variables, etc.).
 
Charles Gray -- Phoenix, AZ  (tcykgreis on skype and=20 google-talk)
-------------------------------1163611484-- --part1_327.10162e6d.328cd6dd_boundary--