Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSean Flanagan
33,235 PointsRuby Objects and Classes -> Variables
Hi. This code won't work. I don't know why.
class Name
def initialize(title, forename, middle_name, surname)
@title = title
@forename = forename
@middle_name = middle_name
@surname = surname
end
def title
@title
end
def forename
@forename
end
def middle_name
@middle_name
end
def surname
@surname
end
end
name = Name.new("Mr.")
puts name.title +
name.forename +
name.middle_name +
name.surname
Error:
name.rb:3:in `initialize': wrong number of arguments (1 for 4) (ArgumentError)
from name.rb:27:in `new'
from name.rb:27:in `<main>'
I'd be grateful please to know how to correct this. :-)
2 Answers
George Klooney
499 Points"name = Name.new("Mr.")" You need to pass all 4 arguments when calling new.
Sean Flanagan
33,235 PointsThanks George. That was a big help! :-)