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