Something new undefined method

Perhaps it is better to move away from the DBI fetch_hash method and go back
to using hardcoded instance variables for example

@projectCode = @data[‘prj_id’]
@projectName = @data[‘prj_name’]

def projectName=(val)
@projectName = val if val
return @projectName
end

??
Graeme Matthew
Analyst Programmer
Mercer Investment Consulting
Level 29, 101 Collins Street, Melbourne, VIC, 3001, Australia
Tel - 61 3 9245 5352 Fax - 61 3 9245 5330
visit http://www.merceric.com

···

-----Original Message-----
From: Hal E. Fulton [mailto:hal9000@hypermetrics.com]
Sent: Friday, 20 September 2002 13:42
To: ruby-talk@ruby-lang.org
Subject: Re: Something new undefined method

----- Original Message -----
From: “Matthew, Graeme” Graeme.Matthew@mercer.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, September 19, 2002 10:15 PM
Subject: Something new undefined method

Here is one I have not encountered :

c:/dev/cgi-bin/Project.rb:29:in projectCode': undefined method ’ for
nil
(NameError)

undefined method but I cannot see a problem with this

def projectCode
return @data[‘prj_id’]
end

It’s a runtime error (the most common one I see).
Apparently @data has the value nil when you
try to apply to it…

Hal

__


This e-mail and any attachments may be confidential or legally privileged.
If you received this message in error or are not the intended recipient, you
should destroy the e-mail message and any attachments or copies, and you are
prohibited from retaining, distributing, disclosing or using any information
contained herein. Please inform us of the erroneous delivery by return
e-mail.

Thank you for your cooperation.


ec03/04

Hi –

Perhaps it is better to move away from the DBI fetch_hash method and go back
to using hardcoded instance variables for example

@projectCode = @data[‘prj_id’]
@projectName = @data[‘prj_name’]

def projectName=(val)
@projectName = val if val
return @projectName
end

??

It looks like you’re defining the instance variables in the wrong
scope. If you do:

class A
@ivar = 1
def thing
puts @ivar # nil
end
end

the i.v. @ivar is an instance variable of class A, not of instances of
class A. You’d want to do something like:

class A
def initialize
@ivar = 1
end
def thing
puts @ivar # 1
end
end

David

···

On Fri, 20 Sep 2002, Matthew, Graeme wrote:


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com