Skip to content
Related Articles
Open in App
Not now

Related Articles

Ruby | Numeric positive? function

Improve Article
Save Article
Like Article
  • Last Updated : 01 Feb, 2022
Improve Article
Save Article
Like Article

The positive?() is an inbuilt method in Ruby returns a boolean value. It returns true if the number is a positive one, else it returns false.  

Syntax: num.positive?()
Parameters: The function needs a number which is to be checked for. 
Return Value: It returns returns a boolean value.

Example 1

CPP




# Ruby program for positive?()
# method in Numeric
 
# Initialize a number
num1 = 15
 
# Prints positive or not
puts num1.positive?()

Output:  

true

Example 2

CPP




# Ruby program for positive?()
# method in Numeric
 
# Initialize a number
num1 = -15
 
# Prints positive or not
puts num1.positive?()

Output

false
My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!