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

I can't remember the operator that gives me the remainder of the operator

please answer this as soon as possibl

method.rb
def mod(a, b)
  puts mod/b
end

3 Answers

This code will pass that challenge - I just looked it up for you:

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

You need to return the result of the modulus operation from the method.

Steve.

Do you mean the % operator?

Actually Ruby automatically returns the result of the last expression evaluated, so why should we manually return the value?

Yeah - good point. I've been in Java all week so forgot that. Some would say adding the explicit return keyword adds clarity; others would say it doesn't. The code challenge accepts either version.