From: Brian Candler on 26 Feb 2010 04:04 Alex Alex wrote: > What class have object "current_item"? In general you won't know until you run your code, as you've not shown any code which adds something to @items. For example: cart = Cart.new product = Flurble.new cart.items << product cart.add_product(product) In this case, current_item will be of class Flurble. -- Posted via http://www.ruby-forum.com/.
From: Alex Alex on 26 Feb 2010 04:09 Brian Candler wrote: > Alex Alex wrote: >> What class have object "current_item"? > > In general you won't know until you run your code, as you've not shown > any code which adds something to @items. For example: > > cart = Cart.new > product = Flurble.new > cart.items << product > cart.add_product(product) > > In this case, current_item will be of class Flurble. Yes, you're right: def add_product(product) current_item = @items.find {|item| item.product == product} if current_item current_item.increment_quantity else @items << CartItem.new(product) end end in my case current_item w'll be of class "CartItem" Thank you for reply -- Posted via http://www.ruby-forum.com/.
First
|
Prev
|
Pages: 1 2 Prev: RubyZip help needed Next: Error on iterating through a set of nested tables in a form |