Ruby Ruby Collections Build a Grocery List Program Build a Grocery List Program: Part 1

What does this line of code do?

hash = { "name" => name, "items" => }

I know it's creating a hash. But what does the => do?

1 Answer

Ling Lei
Ling Lei
6,083 Points

=> is assigning / mapping the value. In other languages hash can be called something like dictionary.

so the first has item has a key of "name" and a value of the variable name and the second hash value has the key of "items" and the value of an array.