Class Help, undifined local var or meth

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

On 7/12/06, Ryan Edwards-Crewe [email protected] 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/.


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

Robert D. wrote:

On 7/12/06, Ryan Edwards-Crewe [email protected] 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)

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

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

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…

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…

aPOlist = POList.new

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

THAT’S RIGHT! Thanks a bunch

Crewe

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs