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 Variables

Vishakha Agarwal
Vishakha Agarwal
9,130 Points

Getting error message

class Name
    def intialize(title, first_name, middle_name, last_name)
        @title = title
        @first_name = first_name
        @middle_name = middle_name
        @last_name = last_name
    end
    def title
        @title
    end

    def first_name
        @first_name
    end 

    def middle_name
        @middle_name
    end

    def last_name
        @last_name
    end
end

name = Name.new("Ms.", "Vishakha", "", "Agarwal")
puts name.title +
     name.first_name + 
     name.middle_name +
     name.last_name

Each time I run this code, I get the following error message:

name.rb:25:in initialize': wrong number of arguments (4 for 0) (ArgumentError) from name.rb:25:innew' from name.rb:25:in `<main>'

However if I run the code with out passing any arguments it would work and give 4 blank lines

Code:

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

2 Answers

Daniel Cunningham
Daniel Cunningham
21,109 Points

you misspelled "initialize", so it isn't recognizing the code you wrote for the initialize statement.