Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
integer
communitycreator

What is the integer.remainder() method in Ruby?

okwudili onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The remainder() method of an integer instance returns the remainder after dividing a particular integer by another.

Syntax

Here is the syntax for this method:

int1.remainder(int2)

Parameters

int2: This is the divisor. It is used to divide the integer int1, which invokes the remainder() method.

Return value

The value returned is the remainder after dividing int1 and int2.

Code example

# create integer values
int1 = 2
int2 = 34
int3 = 5
int4 = 12

# get remainders of integer values
puts int1.remainder(1)
puts int2.remainder(3)
puts int3.remainder(5)
puts int4.remainder(100)
Get the remainder values of some integer values after division

Code explanation

  • Lines 2–5: We create some integer values.
  • Lines 8–11: We use the remainder() method to get the remainder of some integer values. Then, we print the results to the console.

RELATED TAGS

ruby
integer
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring