Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Collections Build a Grocery List Program Create a Method That Returns a Hash

Brian Patterson
Brian Patterson
19,588 Points

Why isn't this working?

'def create_shopping_list hash = { "name"=> name } return hash

end ' Not sure why this does not work?

def create_shopping_list
  hash = { "name"=> name }
  return hash


1 Answer

Rick Buffington
Rick Buffington
Courses Plus Student 8,037 Points

From what I can tell, it looks like you are trying to assign the key "name" with a value that Ruby thinks is a variable. Ruby is looking for a variable named "name" because you have not enclosed the value in quotes - or have not assigned a value to name.

hash = { "name" => "name" }

If what you are trying to do is assign the value with the "name" variable, you'd need to declare and assign it before using it in the hash:

name = "John"
hash = { "name" => name }

Hope that helps.

Brian Patterson
Brian Patterson
19,588 Points

Thanks now stuck on the next bit.