thanks for the help, i am willing to use the attr_reader, attr_writer
options however the problem with these is that lets say you need to trigger
of some events when an attribute is set, then how would you do it through
attr_reader / writer ?
I also thought the whole aim of def projectName=(val) was to act as a getter
/ setter attribute ?
Mercer Investment Consulting
Level 29, 101 Collins Street, Melbourne, VIC, 3001, Australia
Tel - 61 3 9245 5352 Fax - 61 3 9245 5330
Matthew, Graeme wrote:
I’m just not getting this!
What am I doing wrong here, this is taking way to long
DisplayProject': undefined methodprojectName’ for #Project:0x25dfae0 (NameError)
OK, I know you can read, but just to clarify: this error message is
telling you that you’re trying to call an instance method named
"projectName" for the “Project” class, but there is no instance method
by that name.
I’m now using instance variables
@projectName = val if val
This looks fine, but keep in mind that “projectName=()” (a "setter"
method) and “projectName()” (a “getter” method) are two different
but it’s failing here in my document:
Although we can’t see all of the code for your “Project” class, I’m
guessing that you didn’t define a “projectName” accessor method to
complement the “projectName=” method. A quick way to do this (since you
also have a “@projectName” instance variable) is to use the attr_reader
class Project attr_reader :projectName end
A more verbose (but otherwise equivalent) way to do it is to explicitly
code-up the method:
class Project def projectName @projectName end end
If you don’t already have “Programming Ruby” (a.k.a. the “Pickaxe” book)
I’d recommend you pick up a copy. It’s also available for free online.
The second chapter:
has a section entitled “Objects and Attributes” that does a very nice
job of explaining what’s going on.
Hope this helps,
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
Thank you for your cooperation.