Ruby Integer prime? function with example
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.even?
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 program for prime? function # Pre-defined class require 'prime' # Initializing the numbers num1 = 100num2 = 17num3 = 90num4 = 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 program for prime? function # Pre-defined class require 'prime' # Initializing the numbers num1 = 13num2 = 19num3 = 18num4 = 10 # Printing if prime or not puts num1.prime? puts num2.prime? puts num3.prime? puts num4.prime? |
Output:
true true false false
Recommended Posts:
- Ruby Integer integer? function with example
- Ruby | Integer >= function
- Ruby | Integer <=> function
- Ruby | Integer << function
- Ruby Integer odd? function with example
- Ruby Integer div() function with example
- Ruby | Integer - function
- Ruby Integer lcm() function with example
- Ruby Integer gcd() function with example
- Ruby Integer abs() function with example
- Ruby Integer next function with example
- Ruby Integer chr function with example
- Ruby Integer even? function with example
- Ruby Integer to_f function with example
- Ruby Integer to_i function with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



