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 trial

Ruby Ruby Objects and Classes Variables and Methods Attribute Writers and Accessors

MICHAEL P
MICHAEL P
5,191 Points

Even though I followed the video, and did EVERYTHING that Jason did in the video, my code does not work! Please help!

Hi, even though I followed the video, and did EVERYTHING that Jason did in the video, my code does not work! I keep getting error messages.

My error code when I attempt to run name.rb :

name.rb:4:in 'initialize' : wrong number of arguments (given 1, expected 4) (ArgumentError) from name.rb:25: in 'new' from name.rb:25: in '<main>'

Here is my code. I would appreciate help!

class Name attr_reader :title, :first_name, :middle_name, :last_name

def initialize(title, first_name, middle_name, last_name) @title = title @first_name = first_name @middle_name = middle_name @last_name= last_name end

end def first_name @first_name end

def middle_name @middle_name end

def last_name @last_name end

name = Name.new("Mr.") puts name.title + " " + name.first_name + " " + name.middle_name + " " + name.last_name

2 Answers

Abhishek Sisodia
Abhishek Sisodia
16,203 Points

you need to give more information to initialize method, as suggested by given error

'initialize' : wrong number of arguments (given 1, expected 4) (ArgumentError)

following code will help you

name = Name.new("Mr.", "Jason", "Treehouse", "Seifer")