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 Build a Grocery List Program Create a Method That Returns a Hash

Need help

Totally confused here.

shopping_list.rb
def create_shopping_list
  Hash.new(create_shopping_list)   
  return hash
end

2 Answers

Stephen Gheysens
Stephen Gheysens
11,935 Points

Hi Marguerite,

Your function is trying to return a variable "hash" that doesn't exist.

Inside of the function, your first line Hash.new(create_shopping_list) is creating a hash, then trying to insert create_shopping_list into it. For an empty hash, just use Hash.new().

After you create the empty hash, you need to return it. you can do this in two lines (by assigning the new hash to a variable) or one line (return the new hash directly):

def create_shopping_list
  h = Hash.new()
  return h
end

or

def create_shopping_list
  return Hash.new()
end

Let me know if you have any questions!

Thanks, Stephen

Thanks so much for the clarification.