Ruby Modulo

christian.dinh's avatar
Published Jul 27, 2021Updated Sep 9, 2021
Contribute to Docs

A Ruby function that returns the modular value, the remainder, when two numbers are divided.

  • Learn to program in Ruby, a flexible and beginner-friendly language used to create sites like Codecademy.
    • Beginner Friendly.
      9 hours
  • Learn the basics of building applications with this convenient and powerful web development framework.
    • With Certificate
    • Intermediate.
      6 hours

Syntax

x.modulo(y)
  • where x is the dividend and y is the divisor. Two values are required.

Example 1

puts 5.modulo(3)
# Output: 2
  • 5 is divided by 3 and the remainder is 2.

Example 2

puts 10.modulo(3)
# Output: 1
  • 10 is divided by 3 and the remainder is 1.

All contributors

Contribute to Docs

Learn Ruby on Codecademy

  • Learn to program in Ruby, a flexible and beginner-friendly language used to create sites like Codecademy.
    • Beginner Friendly.
      9 hours
  • Learn the basics of building applications with this convenient and powerful web development framework.
    • With Certificate
    • Intermediate.
      6 hours