Forum: Ruby on Rails a problem with instance and local variables

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5c1cc7254a2315c4db633e588c9b5f5c?d=identicon&s=25 Ahmed Khademzadeh (Guest)
on 2009-05-09 17:19
(Received via mailing list)
Hi all,

on page 151 of the book agile... we have the following code in the
file order.rb:

def add_line_items_from_cart(cart)
   cart.items.each do |item|
   li = LineItem.from_cart_item(item)
   line_items << li
end

what kind of variable is line_items? is it a local, class, instance or
other kind of variable?
if it is local how rails saves the contents of this variable when
saves the order in "save_order" method which is place in the file
"store_controller.rb"?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-09 17:23
(Received via mailing list)
On May 9, 7:12 am, Ahmed Khademzadeh <khademza...@gmail.com> wrote:
>
> what kind of variable is line_items? is it a local, class, instance or
> other kind of variable?

Assuming the code is correct (you're missing an 'end' for starters),
the only way this could work were if line_items were a method
returning an appropriate object.

Fred
This topic is locked and can not be replied to.