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:
num1 = 100
num2 = 17
num3 = - 90
num4 = - 29
puts num1.pred
puts num2.pred
puts num3.pred
puts num4.pred
|
Output:
99
16
-91
-30
Example 2:
num1 = 19
num2 = - 17
num3 = - 18
num4 = 16
puts num1.pred
puts num2.pred
puts num3.pred
puts num4.pred
|
Output:
18
-18
-19
15
Share your thoughts in the comments
Please Login to comment...