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

Jory Braun
Jory Braun
7,814 Points

where are you calling to_s how is it being called?

...

1 Answer

Stone Preston
Stone Preston
42,016 Points

at 0:53 he states: Whenever we print something out to the screen using the puts method, internally Ruby is calling to string on it or to_s.

so you dont call the method yourself, ruby calls the to_s method you defined whenever you puts the class

Jory Braun
Jory Braun
7,814 Points

I zoned out when he said that, i realised right after my question.

But what about the argument passed in like in puts name, if we over ride to_s to print "bla". What will happen? name will be printed?