Skip to content
Related Articles

Related Articles

Improve Article

Ruby Integer pred() function with example

  • Last Updated : 07 Jan, 2020

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 immediate predecessor of the number, i.e., it returns number – 1

Example 1:






# Ruby program for pred function
   
# Initializing the numbers 
num1 = 100
num2 = 17
num3 = -90
num4 = -29
     
# Printing the pred value
puts num1.pred
puts num2.pred
puts num3.pred 
puts num4.pred 

Output:

99
16
-91
-30

Example 2:




# Ruby program for pred function
   
# Initializing the numbers 
num1 = 19
num2 = -17
num3 = -18
num4 = 16
       
# Printing the pred value
puts num1.pred
puts num2.pred
puts num3.pred 
puts num4.pred

Output:

18
-18
-19
15
My Personal Notes arrow_drop_up
Recommended Articles
Page :