0

I'm working on a small video game on the console where I have a main config hash that stores values for the game. When I try to access keys in an array in that hash, they don't return anything. Am I doing something wrong?

cfg =
{
    :gameVersion => 1.0,
    :invPouch => ['flint', 'string'],
    :gold => 50
}

puts cfg[:invPouch[1]]

1 Answer 1

6

It should be:

puts cfg[:invPouch][1]

In your case, :invPouch[1] is "n", and cfg["n"] gives you nil.

Sign up to request clarification or add additional context in comments.

1 Comment

answer in form of a runnable snippet: rubysandbox.com/#/snippet/5673f3fac55987000c000000

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.