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!

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 Basics (Retired) Ruby Methods Method Returns: Part 1

Winston Quin
Winston Quin
10,359 Points

Why does the correct answer include an "=" sign? I never saw this in the video.

I worked out the answer with experimentation, but never found at which point in the preceding videos this was mentioned. I'm having trouble on the next challenge, and think an explanation might help me.

so this is correct:

def mod(a, b) puts = a % b end

and this is not:

def mod(a, b) puts a % b end

but I don't understand why

def mod(a, b)
  puts = a % b

3 Answers

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! To be honest, I'm not sure why your code passed other than to say that every Ruby block returns a value. However, the challenge never asked you to print anything. It asked you to return a value. At 0:38 of the preceding video the return statement is first used. It is, of course, entirely different than the puts statement.

The answer it was expecting (I believe) was:

def mod(a, b)
  return a % b

I know that it has something to do with "implicit return" values in Ruby, but I'm far from an expert. I do know that because every Ruby block returns a value, it would seem to me that the result in your second variant is assigned to puts which results in the correct value being returned while the puts a % b probably results in an object being returned.

Hope this helps! :sparkles:

Technically all you need is:

def mod(a, b)
  a % b

Remember the return is implied, and it is asking to "return" not to print, so you do not need the "put" keyword, you could use the "return" keyword instead. Cheers.

= is an assignment operator

so you have assigned a variable called puts to the value of a % b