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 The to_s method

Why dont you need a print statement here

WHy dont you need to write puts to print in a method.

For example we have:

def to_s

where is the print statement here we dont use print or puts.

full_name_with_title is defined as :

  def full_name_with_title
    @title + " " + full_name()

there is not print there either

1 Answer

Michael Hulet
Michael Hulet
47,842 Points

print and puts write a string to the console, which is rarely something you'll want to do, outside of debugging. Instead, in Ruby, the last statement in a method is what that method returns (though you can explicitly write out the return keyword for the same effect, if you want). returning a value from a method makes it so you can use the value that the method generates at other places in your code, including print it out later, if you want