# Re: Multidimensional Arrays

**URL:** <https://www.ruby-forum.com/t/re-multidimensional-arrays/76107>\
**Category:** Ruby\
**Created:** [November 15, 2006, 10:43pm UTC](https://www.ruby-forum.com/t/re-multidimensional-arrays/76107 "2006-11-15T22:43:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 15, 2006, 10:43pm UTC](https://www.ruby-forum.com/t/re-multidimensional-arrays/76107/1 "2006-11-15T22:43:55Z")

</div>

> chessboard = Array.new(8) {|idx| Array.new(8, “”)}  
> chessboard[3][3] = “pawn”
> 
> This will do what you expect. Read the documentation for Array.new It  
> will explain all these subtle nuances.
> 
> Blessings,  
> TwP

Thanks. That works great. I read and tried to understand the  
documentation  
for Array.new but failed to understand what I read 🙂 It’s nice that I  
don’t  
have to store the allotted dimensions. It returns an error message if  
the  
first number is out of range. If the second number is out of range, it  
makes that  
particular array longer.

Now all I have to do is file that information away somewhere when I can  
find  
it when I need it.

Charles G. – Phoenix, AZ … where you can bake the chill out of your  
bones.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [November 15, 2006, 11:01pm UTC](https://www.ruby-forum.com/t/re-multidimensional-arrays/76107/2 "2006-11-15T23:01:44Z")

</div>

U might just use this.

class Array2D \< Array

```
# Inicializamos
def initialize(width, height)
 		@data = Array.new(width) { Array.new(height) }
end

# Definimos el metodo de indexacion para tratarlo como array en C.
def [](x, y)
 		@data[x][y]
end

# Definimos el metodo de asignacion igual que el de indexacion
def []=(x, y, value)
 		@data[x][y] = value
end

```

end

ChessBoard = Array2D.new(8,8)
