1

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.

2
  • What do you mean by name? An array in ruby has only indexes, not 'names'... Maybe what you're looking for is a Hash? Commented Mar 15, 2012 at 10:46
  • A Hash is absolutely more suited, yes. Thanks. Commented Mar 15, 2012 at 10:51

1 Answer 1

2

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]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.