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

I get an error trying to run the last part of this Variables video

class Fede
  def initialize(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 = Fede.new("Mr")
puts name.title + " " +
name.first_name + " " +
name.middle_name + " " +
name.last_name

And this is the Error message I get

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

Please, help

I kinda solved this by thinking about it and doing this, but is this mentioned in the video?

name = Fede.new("Mr", "Barack", "Hussain", "Obama")

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I answered this here:

https://teamtreehouse.com/forum/for-me-this-code-doesnt-pass-unless-you-pass-in-the-new-4-parameters

There was a cutscene where I'm pretty sure more stuff got changed than we see in the video.

The line near the bottom should say:

name = Fede.new("Mr", "Jason", "", "Seifer")

thanks, sorry, I thought about it for a while than managed to solve it by myself, I just went through the video a couple of times but couldnt find it :(

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Yeah, Jason doesn't show this part and it just has to be there :). Otherwise the code will never work.