BSG
BSG

Reputation: 1452

Populating array (by 'name') in array of arrays

Lets say i have an array of arrays, of which i dont know the names, just that they are arrays, and how many of them there are.

bigArray=[smallArrayA[], smallArrayB[]]

Now i can fetch the array(s) by indexposition, like:

smallA = bigArray[0]
smallA << 'input'

But what i'd like to know is the names of the arrays, stored in the 'big' one..

bigArray.inspect

..just gives me:

[['input'],[]]

My problem is that the names of the smaller ones are going to be created dynamiclly, and i need to know their names to modify the right one, later on.

Upvotes: 1

Views: 122

Answers (1)

seph
seph

Reputation: 6076

Sounds like you need a hash:

bigHash = { :a => smallArrayA, :b => smallArrayB }

Now you can refer to each element of the hash by name:

bigHash[:a]

Upvotes: 2

Related Questions