Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Collections Ruby Arrays Adding Items to Arrays

How to store an instance variable in an array

Hey everyone!

items = "milk"

grocery_list = [milk]

grocery_list ...returns... "milk"

Why is that? Why isn't the instance variable items stored in there, instead of the value?

Thanks in advance

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Please explain. I'm not sure I understand the question when confronted with the code. If grocery_list = ["milk"], then grocery list only has one item with index [0] and value "milk". You didn't put items` variable anywhere, so you can't expect it to be anywhere.

Ah okay.. this is what I was looking for. Sorry for the confusion :( still learning.