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 immediate predecessor of the number, i.e., it returns number – 1
Example 1:
# Ruby program for pred function # Initializing the numbers num1 = 100num2 = 17num3 = -90num4 = -29 # Printing the pred valueputs num1.predputs num2.predputs num3.pred puts num4.pred |
Output:
99 16 -91 -30
Example 2:
# Ruby program for pred function # Initializing the numbers num1 = 19num2 = -17num3 = -18num4 = 16 # Printing the pred valueputs num1.predputs num2.predputs num3.pred puts num4.pred |
Output:
18 -18 -19 15


