Is it possible to do something like this?
customer1.shopping_cart.each do |item| puts("#{item.name}")
The Item class has an attr_reader for the instance variable name.
Item
attr_reader
customer1.shopping_cart.each do |item| puts("#{item.name}") end
This will put names for every item from the customer1.shopping_cart collection (presumably array or set)
customer1.shopping_cart
UPD: A bit more idiomatic syntax:
customer1.shopping_cart.map(&:name).each(&method(:puts))
This will put names for every item from the
customer1.shopping_cart
collection (presumably array or set)UPD: A bit more idiomatic syntax: