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 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 :)