Friday, January 15, 2010

[Rails] Re: Agile Web Dev (book) question: errors

> class Cart
>   attr_reader :items
>
>   def initialize
>       @items = []
>   end
>
>   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
> end
>
> It seems to me that there is one too many "end"s here.
>

Looks okay to me. The first "end" closes the "if-else" block
The second "end" closes the "def" method
The third "end" closes the "class" declaration

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate