Marcin Mielzynski
9/17/2006 12:33:00 PM
Edward wrote:
> Both of these code examples for making class properties don't work
> although they are pretty much straight out of the book "Programming
> Ruby". What I am doing wrong here?
>
> error is: undefined method `firstName' for #<User:0xb7f76b24
> @firstName="Newton"> (NoMethodError)
> ----------------------
you didn't create an attribute reader:
attr_accessor :firstName - creates both reader and writer
attr_writer :firstName - creates a writer
attr_reader :firstName - creates a reader (the one that you need)
You can also create a reader by hand:
def firstName
@firstName
end
lopex