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
20,723 Points

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