# A problem with instance and local variables

**URL:** <https://www.ruby-forum.com/t/a-problem-with-instance-and-local-variables/167583>\
**Category:** Rails\
**Created:** [May 9, 2009, 5:19pm UTC](https://www.ruby-forum.com/t/a-problem-with-instance-and-local-variables/167583 "2009-05-09T17:19:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@Ahmed\_K](https://www.ruby-forum.com/u/Ahmed_K)\
**Post date:** [May 9, 2009, 5:19pm UTC](https://www.ruby-forum.com/t/a-problem-with-instance-and-local-variables/167583/1 "2009-05-09T17:19:19Z")

</div>

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”?

---

<div class="post-metadata">

**Author:** ![Ahmed\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@Ahmed\_K](https://www.ruby-forum.com/u/Ahmed_K)\
**Post date:** [May 9, 2009, 5:23pm UTC](https://www.ruby-forum.com/t/a-problem-with-instance-and-local-variables/167583/2 "2009-05-09T17:23:24Z")

</div>

On May 9, 7:12 am, Ahmed K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
