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 values
int1 = 5
int2 = 100
int3 = 0
int4 = -1
# get successors
puts int1.succ # 6
puts int2.succ # 101
puts int3.succ # 1
puts 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 succ method. Then, the results are printed to the console.

Free Resources