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.
Thomas Minnick2,539 Points
I don't get the difference between Puts, Return, and Print ?
Whenever They are used in the video i don't understand the difference between them.
Ari Misha19,268 Points
puts adds a newline to the end of each argument if there is not one already.
print does not add a new line.
puts [[1,2,3], [4,5,nil]] Would return: 1 2 3 4 5
Whereas print [[1,2,3], [4,5,nil]] would return:
Notice how puts does not output the nil value whereas print does.
Now "Return" is something different from both "print" and "puts". It doesnt print anything to the console. What does it do then? Well, it "returns" a value which will be available to use later throughout your code. In your career as a programmer, you use "puts" or "print" when you wanna output a string but you're going to use "return" a lot like a lot when you're using functions to add different functionality to your application.
And Ruby does an implicit "return", means if the last statement returns something , you dont have to write unnecessary "return" keyword over and over coz Ruby knows what needs to be returned. I hope it helped. (: