ruby - Accessing instance variable in `each` loop -


is possible this?

customer1.shopping_cart.each |item|   puts("#{item.name}") 

the item class has attr_reader instance variable name.

customer1.shopping_cart.each |item|   puts("#{item.name}") end 

this put names every item customer1.shopping_cart collection (presumably array or set)

upd: bit more idiomatic syntax:

customer1.shopping_cart.map(&:name).each(&method(:puts)) 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -