The next function in Ruby returns the immediate successor of the number, i.e., it returns number + 1. If a float value is used, it throws an error message.
Ruby
Output:
Ruby
Output:
Syntax: number.next Parameter: The function takes the integer whose next is to be returned. Return Value: The function returns the immediate successor of the number, i.e., it returns number + 1Example #1:
# Ruby program of next function
# Initializing the numbers
num1 = 100
num2 = 17
num3 = -90
num4 = -29
# Printing the modulo value
puts num1.next
puts num2.next
puts num3.next
puts num4.next
101 18 -89 -28Example #2:
# Ruby program of next function
# Initializing the numbers
num1 = 19
num2 = -17
num3 = -18
num4 = 16
# Printing the modulo value
puts num1.next
puts num2.next
puts num3.next
puts num4.next
20 -16 -17 17