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

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()
  end

there is not print there either

1 Answer

Michael Hulet
Michael Hulet
47,912 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