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 trialNadezhda Oorzhak
2,716 PointsReturn method
Hi to all,
Please, explain why we need here Return method? Is it kind of storing the future value? I don't clear understand what exactly it returns and to where.
def get_name() print "Enter your name: " return gets.chomp end name = get_name()
Thank you very much for explaining in advance!
2 Answers
Zach Stearman
10,913 PointsHi, Nadezhda!
The return method simply controls what the output of your method is. In this lesson, you create a method called get_name(), so the return method tells the program what the output of the get_name() method should be. In this case, the output is just the gets.chomp string, so the program would actually function if you left return off, but if you wanted to manipulate that string anymore or do something more complex, return allows you to clearly define what the method will output.
Hope this helps!
Nadezhda Oorzhak
2,716 PointsHi, Zach!
Thank you very much! The idea turns out to be very simple. Sometimes, when an example is so simple, it's more difficult to understand the logic.
Thanks again, now i clearly understand!