Ruby Integer prime? function with example Last Updated : 03 Dec, 2020 Comments Improve Suggest changes Like Article Like Report The prime? function in Ruby returns a boolean value. It returns true if the number is prime, else it returns false. It requires the 'prime' class to be pre-added. Syntax: number.prime? Parameter: The function takes the integer which is to be checked for prime or not. Return Value: The function returns a boolean value which determines if the value is prime or not. Example 1: Ruby # Ruby program for prime? function # Pre-defined class require 'prime' # Initializing the numbers num1 = 100 num2 = 17 num3 = 90 num4 = 29 # Printing if prime or not puts num1.prime? puts num2.prime? puts num3.prime? puts num4.prime? Output: false true false true Example 2: Ruby # Ruby program for prime? function # Pre-defined class require 'prime' # Initializing the numbers num1 = 13 num2 = 19 num3 = 18 num4 = 10 # Printing if prime or not puts num1.prime? puts num2.prime? puts num3.prime? puts num4.prime? Output: true true false false Comment More infoAdvertise with us Next Article Ruby Integer prime? function with example G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Integer-class Similar Reads Ruby Integer pred() function with example The pred function in Ruby returns the immediate predecessor of the number, i.e., it returns number - 1. If a float value is used, it throws an error message. Syntax: number.pred Parameter: The function takes the integer whose predecessor is to be returned. Return Value: The function returns the imme 1 min read Ruby Integer lcm() function with example The lcm() function in Ruby returns the lcm of two numbers. LCM signifies the lowest common multiple which is divisible by both the numbers. Syntax: number1.lcm(number2) Parameter: The function requires two numbers whose lcm is returned. Return Value: The function returns the lcm of two numbers Examp 1 min read Ruby Integer to_r function with example The to_r function in Ruby converts the value of the number to a rational. Syntax: number.to_r Parameter: The function takes the number which is to be converted to a rational number. Return Value: The function returns the rational number. Example #1: Ruby # Ruby program for to_r function # Initializi 1 min read Ruby Integer next function with example The next function in Ruby returns the immediate successor of the number, i.e., it returns number + 1. If a float value is used, it throws an error message. Syntax: number.next Parameter: The function takes the integer whose next is to be returned. Return Value: The function returns the immediate suc 1 min read Ruby Integer remainder() function with example The remainder() function in Ruby returns the remainder when two numbers are divided. Syntax: (number1).remainder(number2) Parameter: The function takes two number number1 and number2 whose integer division and remainder is returned. Return Value: The function returns the remainder. Example 1: Rub 1 min read Like