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

MICHAEL P
MICHAEL P
5,190 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")