Ruby - What's the best way to create a 3-dimensional array?

For general discussion related FlowStone
Post Reply
zoobooboozoo
Posts: 32
Joined: Tue Sep 23, 2014 12:14 pm

Ruby - What's the best way to create a 3-dimensional array?

Post by zoobooboozoo »

Hi guys,
I'm new to ruby and flowstone and I want to know what's the best methods for creating a 3-dimensional array, I've seen some different methods online and thought I'd better get your input on that.

The array dimensions are: 25, 3, 5 (not that it matter so much :) )

thx i advance for the help.

also: I had a problem with the knobs. when I take a knob and connect its output to ruby input it the corresponding value inside the ruby module doesn't update when I turn the knob around. how can I solve this?
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Ruby - What's the best way to create a 3-dimensional arr

Post by tulamide »

zoobooboozoo wrote:I'm new to ruby and flowstone and I want to know what's the best methods for creating a 3-dimensional array, I've seen some different methods online and thought I'd better get your input on that.

Nesting blocks is a comfortable way to create multi-dimensional arrays:

Code: Select all

a3d = Array.new(4) {Array.new(3) {Array.new(2)} }


Accessing that array's cells is also straight-forward:

Code: Select all

a3d[0][1][1] = 5
n = a3d[2][0][0]
"There lies the dog buried" (German saying translated literally)
zoobooboozoo
Posts: 32
Joined: Tue Sep 23, 2014 12:14 pm

Re: Ruby - What's the best way to create a 3-dimensional arr

Post by zoobooboozoo »

Thanks, works great.
Post Reply