Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Objects and Classes Variables and Methods Instance Variables and Local Variables

why does "name.first_and_middle_name" variable after changing it to instance variable contains only "jason"

why does "name.first_and_middle_name" variable after changing it to instance variable contains only "jason", not like what was stated inside the full_name method, where @first_and_middle_name = @first_name + " " + @middle_name + " " + @last_name , which means that name.first_and_middle_name must contains the whole name with the title "mr. jason seifer"

2 Answers

Maximiliane Quel
PLUS
Maximiliane Quel
Courses Plus Student 55,489 Points

Hi,

you are not giving me enough information to answer your question. Where do you only get jason? Why are you expecting something else? name.first_and_middle_name does not sound like a variable that should contain more than jason. If jason does not have a middle name, which it seems he doesn't if the full name is mr. jason seifer

# inside the class
@first_and_middle_name = @first_name + " " + @middle_name

#creating the object without a middle name
name = Name.new("Mr.", "Jason", "", "Seifer")
name.first_and_middle_name

# => Jason

I would only expect you to see the full name with title when you call the full name with title

name.full_name_with_title

# => Mr. Jason Seifer

I found my fault, thanks for help :)

He assigned middle_name to a empty string when initializing:

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

first_name is "Jason" middle_name is ""

definition is -> @first_and_middle_name = @first_name + " " + @middle_name -> Jason + " " + "" = Jason :)