tags:

views:

86

answers:

2

I have a hash that goes multiple levels deep: http://gist.github.com/285350

I am trying to loop through each serving but I keep running into multiple nil[] errors even though the hash isn't nil.

For example:

food_hash["food"]["servings"]

Returns nil.[]

It might be because im half asleep but I can't seem to get down to the "serving_description"... could anyone help put me in the right direction?

+3  A: 

I can't see get down to the "serving_description"

Note that (1) servings.serving is an array, and (2) food is not a key in the hash. Try this instead:

f["servings"]["serving"][0]["serving_description"]
=> "1 thin slice (yield after cooking)"

where f is the hash.

John Feminella
Thanks that worked. I knew it'd be really simple.
dMix
A: 

Is this what you're trying to do?

food_hash["servings"]["serving"][0]["serving_description"]
Ben