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 Ruby Objects and Classes Creating a Class

Is there a way to call the puts method on all of the methods within in the class Name in this video?

Is there a way to call the puts method on all of the methods within in the class Name in this video?

class Name        #class written
  def title
    "Mrs."
  end

  def first
    "Martha"
  end

  def middle
    "Q"
  end

  def last
    "Washington"
  end
end

name = Name.new     #class instantiated
puts name.title     #calling method (title) of class (name)
puts name.first
puts name.middle
puts name.last

just curious

1 Answer

Ron Chan
Ron Chan
10,987 Points

Maybe you can add another method within the Name class:

 def full
    title() + " " + first() + " " + middle() + " " + last()
  end

Then call:

puts name.full