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 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 = 19num2 = -17num3 = -18num4 = 16 # Printing the pred value puts num1.pred puts num2.pred puts num3.pred puts num4.pred |
Output:
18 -18 -19 15
Recommended Posts:
- Ruby Integer integer? function with example
- Ruby Integer odd? function with example
- Ruby Integer div() function with example
- Ruby Integer abs() function with example
- Ruby Integer bit_length function with example
- Ruby Integer ceil function with example
- Ruby Integer chr function with example
- Ruby Integer digits function with example
- Ruby Integer downto() function with example
- Ruby Integer divmod() function with example
- Ruby Integer even? function with example
- Ruby Integer fdiv() function with example
- Ruby Integer floor() function with example
- Ruby Integer gcd() function with example
- Ruby Integer gcdlcm() function with example
- Ruby Integer lcm() function with example
- Ruby Integer magnitude function with example
- Ruby Integer modulo() function with example
- Ruby Integer next function with example
- Ruby Integer succ() 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.

