From: Brian Adkins Date: 2008-11-02T01:43:57+09:00 Subject: Re: n-dimensional array in Ruby Michael Guterl writes: > On Fri, Oct 31, 2008 at 8:09 PM, Christian wrote: >> Hi, >> >> i have a little Java problem, I want to solve using Ruby. Therefor I >> need an n-dimensional array. In Java it looks like this: >> >> double dArray[][][] = new double[x.length()+1][y.length()+1][x.length() >> +y.length()+3]; >> dArray[0][0][0] = 0; >> dArray[0][0][1] = POSITIVE_INFINITY; >> >> Further values will be computed through loops and written into the >> array. >> >> How do I initialize such an array in Ruby? >> > Infinity = 1.0/0 ~$ irb irb(main):001:0> X = 7 => 7 irb(main):002:0> Infinity = 1.0/0 => Infinity irb(main):003:0> 0 / Infinity => 0.0 irb(main):004:0> Infinity * Infinity => Infinity irb(main):005:0> Beyond = Infinity => Infinity irb(main):006:0> 2 * Infinity and Beyond => Infinity irb(main):007:0> Infinity.infinite? => 1 Cool - I just learned about Infinity in Ruby. Hey Dave Thomas, maybe you could add a bit about Infinity in the next relase of Programming Ruby or Programming Ruby 1.9 > > a = [[],[],[]] > a[0][0][0] = 0 > a[0][0][1] = Infinity > > The arrays will grow to whatever size you need them to. > > HTH, > Michael Guterl