What is integer.succ in Ruby?
Overview
The succ method in Ruby is used to return the successor integer of the integer that calls this method.
Syntax
intVal.succ
Parameters
This method does not take any parameters.
Return value
The value returned is the successor integer of the integer value intVal.
Code example
# create integer valuesint1 = 5int2 = 100int3 = 0int4 = -1# get successorsputs int1.succ # 6puts int2.succ # 101puts int3.succ # 1puts int4.succ # 0
Code explanation
- Lines 2–5: We create some integer values.
- Lines 8–11: The successors of the integer values are returned, using the
succmethod. Then, the results are printed to the console.