# Class Help, undifined local var or meth

**URL:** <https://www.ruby-forum.com/t/class-help-undifined-local-var-or-meth/98137>\
**Category:** Ruby\
**Created:** [July 12, 2006, 6:29pm UTC](https://www.ruby-forum.com/t/class-help-undifined-local-var-or-meth/98137 "2006-07-12T18:29:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [July 12, 2006, 6:29pm UTC](https://www.ruby-forum.com/t/class-help-undifined-local-var-or-meth/98137/1 "2006-07-12T18:29:21Z")

</div>

I was using this class before and it was fine until I tried to put it  
into an array, and now I don’t know what’s wrong, I keep getting the  
same  
error, and I’ve check the spellings numerous times…

class PurchaseOrder  
def initialize(po\_number, notes, company, unit\_config, due\_date,  
quantity)  
@po\_number = po\_number  
@notes = notes  
@company = company  
@unit\_config = unit\_config  
@due\_date = due\_date  
@quantity = quantity  
end  
def to\_s  
“#{po\_number}\t#{notes}\t#{company}\t#{unit\_config}\t#{due\_date}\t#{quantity}\n”  
end  
end

class POList  
def initialize  
@purchase\_orders = Array.new  
end  
def append(anOrder)  
@purchase\_orders.push(anOrder)  
self  
end  
def length  
return @purchase\_orders.length  
end  
def   
if key.kind\_of?(Integer)  
@purchase\_orders[key]  
else  
# …  
end  
end  
end

This this line is where I get the error:

aPOlist.append(PurchaseOrder.new("#{po\_number}", “#{notes}”,  
“#{company}”, “#{unit\_config}”, “#{due\_date}”, “#{quantity.to\_i}”))

any ideas…

Crewe

---

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [July 12, 2006, 6:43pm UTC](https://www.ruby-forum.com/t/class-help-undifined-local-var-or-meth/98137/2 "2006-07-12T18:43:03Z")

</div>

On 7/12/06, Ryan Edwards-Crewe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> @notes = notes
> 
> ```
> 
> end
> 
> aPOlist.append(PurchaseOrder.new(“#{po\_number}”, “#{notes}”,  
> “#{company}”, “#{unit\_config}”, “#{due\_date}”, “#{quantity.to\_i}”))
> 
> any ideas…

It might be helpful to indicate the error message you have got.  
It will equally be useful to see where you created aPOlist which I  
suspect  
not to exist.  
Cheers  
Robert

Crewe

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
Deux choses sont infinies : l’univers et la bÃªtise humaine ; en ce qui  
concerne l’univers, je n’en ai pas acquis la certitude absolue.

- Albert Einstein

---

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [July 12, 2006, 6:53pm UTC](https://www.ruby-forum.com/t/class-help-undifined-local-var-or-meth/98137/3 "2006-07-12T18:53:53Z")

</div>

Robert D. wrote:

> On 7/12/06, Ryan Edwards-Crewe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ```
> > @notes = notes
> > 
> > ```
> > 
> > end
> > 
> > aPOlist.append(PurchaseOrder.new(“#{po\_number}”, “#{notes}”,  
> > “#{company}”, “#{unit\_config}”, “#{due\_date}”, “#{quantity.to\_i}”))
> > 
> > any ideas…
> 
> It might be helpful to indicate the error message you have got.  
> It will equally be useful to see where you created aPOlist which I  
> suspect  
> not to exist.  
> Cheers  
> Robert
> 
> Crewe

Here’s the error:

undefined local variable or method `aPOlist’ for main:Object (NameError)

---

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [July 12, 2006, 6:57pm UTC](https://www.ruby-forum.com/t/class-help-undifined-local-var-or-meth/98137/4 "2006-07-12T18:57:03Z")

</div>

Oooo, I see, at least I think, is it because I haven’t Initialized  
aPOlist

aPOlist = nil  
…  
aPOlist.append(PurchaseOrder.new("#{po\_number}", “#{notes}”,  
“#{company}”, “#{unit\_config}”, “#{due\_date}”, “#{quantity.to\_i}”))  
…  
end

---

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [July 12, 2006, 8:13pm UTC](https://www.ruby-forum.com/t/class-help-undifined-local-var-or-meth/98137/5 "2006-07-12T20:13:11Z")

</div>

Ryan Edwards-Crewe wrote:

> > end
> 
> Well that did’t work…

Because you just made aPOlist nil. If you want it to be an array, then:

aPOlist = Array.new

or

aPOlist = []

-Justin

---

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [July 12, 2006, 7:01pm UTC](https://www.ruby-forum.com/t/class-help-undifined-local-var-or-meth/98137/6 "2006-07-12T19:01:49Z")

</div>

Ryan Edwards-Crewe wrote:

> Oooo, I see, at least I think, is it because I haven’t Initialized  
> aPOlist
> 
> aPOlist = nil  
> …  
> aPOlist.append(PurchaseOrder.new("#{po\_number}", “#{notes}”,  
> “#{company}”, “#{unit\_config}”, “#{due\_date}”, “#{quantity.to\_i}”))  
> …  
> end

Well that did’t work…

---

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [July 12, 2006, 8:45pm UTC](https://www.ruby-forum.com/t/class-help-undifined-local-var-or-meth/98137/7 "2006-07-12T20:45:52Z")

</div>

Ryan Edwards-Crewe wrote:

> > aPOlist = nil  
> > …  
> > aPOlist.append(PurchaseOrder.new("#{po\_number}", “#{notes}”,  
> > “#{company}”, “#{unit\_config}”, “#{due\_date}”, “#{quantity.to\_i}”))  
> > …  
> > end
> 
> Well that did’t work…

aPOlist = POList.new

need a refrence to an instnace of POList to then call the append  
method…

---

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [July 12, 2006, 9:00pm UTC](https://www.ruby-forum.com/t/class-help-undifined-local-var-or-meth/98137/8 "2006-07-12T21:00:52Z")

</div>

> aPOlist = POList.new
> 
> need a refrence to an instnace of POList to then call the append  
> method…

THAT’S RIGHT! Thanks a bunch

Crewe

---

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [July 12, 2006, 8:58pm UTC](https://www.ruby-forum.com/t/class-help-undifined-local-var-or-meth/98137/9 "2006-07-12T20:58:18Z")

</div>

Chris H. wrote:

> > Well that did’t work…
> 
> aPOlist = POList.new
> 
> need a refrence to an instnace of POList to then call the append  
> method…

Oh, right. Ignore my message.

-Justin
