[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Class Help, undifined local var or meth

Ryan Edwards-Crewe

7/12/2006 4:30:00 PM

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 [](key)
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

--
Posted via http://www.ruby-....

5 Answers

Ryan Edwards-Crewe

7/12/2006 4:54:00 PM

0

Robert Dober wrote:
> On 7/12/06, Ryan Edwards-Crewe <ryan.edwardscrewe@gmail.com> 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)

--
Posted via http://www.ruby-....

Ryan Edwards-Crewe

7/12/2006 4:57:00 PM

0

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

--
Posted via http://www.ruby-....

Ryan Edwards-Crewe

7/12/2006 5:02:00 PM

0

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...

--
Posted via http://www.ruby-....

Chris Hulan

7/12/2006 6:46:00 PM

0

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...

--
Posted via http://www.ruby-....

Ryan Edwards-Crewe

7/12/2006 7:01:00 PM

0

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

THAT'S RIGHT! Thanks a bunch

Crewe

--
Posted via http://www.ruby-....