E
Edward
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)
----------------------
class User
attr_writer :firstName
def initialize(firstName)
@firstName = firstName
end
end
user = User.new('Hal')
user.firstName = 'Newton'
print user.firstName
--------------------------------
class User
def firstName=(newFirstName)
@firstName = newFirstName
end
def initialize(firstName)
@firstName = firstName
end
end
user = User.new('Hal')
user.firstName = 'Newton'
print user.firstName
--------------------------------
Thanks,
Edward Tanguay
All my projects: http://www.tanguay.info
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)
----------------------
class User
attr_writer :firstName
def initialize(firstName)
@firstName = firstName
end
end
user = User.new('Hal')
user.firstName = 'Newton'
print user.firstName
--------------------------------
class User
def firstName=(newFirstName)
@firstName = newFirstName
end
def initialize(firstName)
@firstName = firstName
end
end
user = User.new('Hal')
user.firstName = 'Newton'
print user.firstName
--------------------------------
Thanks,
Edward Tanguay
All my projects: http://www.tanguay.info