The Wayback Machine - https://web.archive.org/web/20240926232931/https://www.geeksforgeeks.org/ruby-integer-succ-function-with-example/
Open In App

Ruby Integer succ() function with example

Last Updated : 03 Dec, 2020
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The succ 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. 

Syntax: number.succ 

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 + 1

Example 1: 

Ruby




# Ruby program for succ function
  
# Initializing the numbers
num1 = 100
num2 = 17
num3 = -90
num4 = -29
  
# Printing the next value
puts num1.succ
puts num2.succ
puts num3.succ
puts num4.succ


Output: 

101
18
-89
-28

Example 2: 

Ruby




# Ruby program for succ function
  
# Initializing the numbers
num1 = 19
num2 = -17
num3 = -18
num4 = 16
  
# Printing the succ value
puts num1.succ
puts num2.succ
puts num3.succ
puts num4.succ


Output: 

20
-16
-17
17

 



Similar Reads

Ruby | Time succ() function
Time#succ() : succ() is a Time class method which returns the string which returns a new Time object, one second later than time. Syntax: Time.succ() Parameter: Time values Return: a new Time object, one second later than time. Example #1 : # Ruby code for Time.succ() method # loading library require 'time' # declaring time a = Time.new(2019) # dec
2 min read
Ruby | Symbol succ function
Symbol#succ() : succ() is a Symbol class method which returns the next symbol object. Syntax: Symbol.succ() Parameter: Symbol values Return: the next symbol object Example #1 : # Ruby code for Symbol.succ() method # declaring Symbol a = :aBcDeF # declaring Symbol b = :"\u{e4 f6 fc}" # declaring Symbol c = :ABCDEF # Symbol puts "Symbo
2 min read
Ruby Integer integer? function with example
The integer? function in Ruby returns a boolean value. It returns true if the number is an int, else it returns false. Syntax: number.integer? Parameter: The function takes the integer which is to be checked for int or not. Return Value: The function returns a boolean value which determines if the value is int or not. Example #1: # Ruby program of
1 min read
Ruby Integer odd? function with example
The odd? function in Ruby returns a boolean value. It returns true if the number is odd, else it returns false. Syntax: number.odd? Parameter: The function takes the integer which is to be checked for odd or not. Return Value: The function returns a boolean value which determines if the value is odd or not. Example #1: # Ruby program of integer odd
1 min read
Ruby Integer div() function with example
The div() function in Ruby returns the integer division of two numbers. Syntax: (number1).div(number2) Parameter: The function needs two numbers number1 and number2, where number1 is the dividend and number2 is the divisor. Return Value: The function returns the integer division of two numbers. Example #1: # Ruby program of Integer div() function #
1 min read
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
1 min read
Ruby Integer abs() function with example
The abs() function in Ruby returns the absolute value of the integer. Syntax: (number).abs Parameter: The function takes the integer whose absolute value is to be returned. Return Value: The function returns the absolute value of the integer. Example #1: # Ruby program Integer abs() function # Initializing the numbers num1 = -21 num2 = 21 num3 = 0
1 min read
Ruby Integer bit_length function with example
The bit_length function in Ruby returns the number of bits in the value of int. Here number of bits signifies the bit position of the highest bit which is different from the sign bit. In case there is no such bit, zero is returned. Syntax: number.bit_length Parameter: The function takes the number and count its number of bits Return Value: The func
1 min read
Ruby Integer ceil function with example
The ceil function in Ruby returns the smallest number greater than or equal to int with a precision of ndigits decimal digits. The default is considered to be 0. When the precision given is negative, the returned value is an integer with at least ndigits.abs trailing zeros. It returns self when ndigits positive. Syntax: (number).ceil(ndigits) Param
1 min read
Ruby Integer chr function with example
The chr function in Ruby returns the string containing the character represented by the int's value according to encoding. Syntax: string.chr([encoding]) Parameter: The function takes the integer value whose encoding is to be done. It takes a non-mandatory parameter encoding if encoding is to be done according to that. Return Value: The function re
1 min read
Ruby Integer digits function with example
The digits function in Ruby returns the digits place of converting the number to the given base in the parameter. If there is no such parameter is provided, then the default base is taken as 10. Syntax: number.digits(base) Parameter: The function takes the integer whose conversion is to be done. It takes a non-mandatory parameter base to which the
1 min read
Ruby Integer downto() function with example
The downto() function in Ruby returns all the numbers less than equal to number and greater than equal to limit. It iterates the given block, passing in decreasing values from int down to and including limit. If no block is given, an Enumerator is returned instead. Syntax: (number).downto(limit) Parameter: The function takes the integer from which
2 min read
Ruby Integer divmod() function with example
The divmod() function in Ruby returns integer division value and the remainder. Syntax: (number1).divmod(number2) Parameter: The function takes two number number1 and number2 whose integer division and remainder is returned. Return Value: The function returns the integer division value and the remainder. Example #1: # Ruby program of Integer divmod
1 min read
Ruby Integer even? function with example
The even? function in Ruby returns a boolean value. It returns true if the number is even, else it returns false. Syntax: number.even? Parameter: The function takes the integer which is to be checked for even or not. Return Value: The function returns a boolean value which determines if the value is even or not. Example #1: # Ruby program of Intege
1 min read
Ruby Integer fdiv() function with example
The fdiv() function in Ruby returns the floating point result after division of two numbers. Syntax: (number1).fdiv(number2) Parameter: The function needs two numbers number1 and number2, where number1 is the dividend and number2 is the divisor. Return Value: The function returns the floating point division of two numbers. Example #1: # Ruby progra
1 min read
Ruby Integer floor() function with example
The ceil function in Ruby returns the smallest number smaller than or equal to int with a precision of ndigits decimal digits. The default is considered to be 0. When the precision given is negative, the returned value is an integer with at least ndigits.abs trailing zeros. It returns self when ndigits positive. Syntax: (number).floor(ndigits) Para
1 min read
Ruby Integer gcd() function with example
The gcd() function in Ruby returns the gcd of two numbers. GCD signifies the greatest common divisor which divides both the numbers. Syntax: number1.gcd(number2) Parameter: The function requires two numbers whose gcd is to be returned. Return Value: The function returns the gcd of two numbers Example #1: # Ruby program of Integer gcd() function # I
1 min read
Ruby Integer gcdlcm() function with example
The gcdlcm() function in Ruby returns an array with the greatest common divisor and the least common multiple of the two integers. GCD signifies the greatest common divisor which divides both the numbers and lcm signifies the least common multiple of both the numbers Syntax: number1.gcdlcm(number2) Parameter: The function requires two numbers whose
1 min read
Ruby Integer lcm() function with example
The lcm() function in Ruby returns the lcm of two numbers. LCM signifies the lowest common multiple which is divisible by both the numbers. Syntax: number1.lcm(number2) Parameter: The function requires two numbers whose lcm is returned. Return Value: The function returns the lcm of two numbers Example #1: # Ruby program of Integer lcm() function #
1 min read
Ruby Integer magnitude function with example
The magnitude() function in Ruby returns the absolute value of the integer. It is similar to the abs function and is an alias of it. Syntax: (number).magnitude Parameter: The function takes the integer whose magnitude is to be returned. Return Value: The function returns the absolute value of the integer. Example #1: # Ruby program of Integer magni
1 min read
Ruby Integer modulo() function with example
The modulo function in Ruby returns the modulo value of a number by another number. Syntax: number1.modulo(number2) Parameter: The function takes number1 and number2 whose modulo is returned. Return Value: The function returns the modulo value of a number by another number. Example #1: C/C++ Code # Ruby program of modulo function # Initializing the
1 min read
Ruby Integer next function with example
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. 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 + 1
1 min read
Ruby Integer times function with example
The times function in Ruby returns all the numbers from 0 to one less than the number itself. It iterates the given block, passing in increasing values from 0 up to the limit. If no block is given, an Enumerator is returned instead. Syntax: (number).times Parameter: The function takes the integer till which the numbers are returned. It also takes a
2 min read
Ruby Integer to_d() function with example
The to_d function in Ruby converts the value of int as a BigDecimal. Syntax: number.to_d Parameter: The function takes the integer which is to be converted to BigDecimal. Return Value: The function returns the BigDecimal value of int. Example #1: # Ruby program for to_d function require 'bigdecimal' require 'bigdecimal/util' # Initializing the numb
1 min read
Ruby Integer to_f function with example
The to_f function in Ruby converts the value of the number as a float. If it does not fit in float, then it returns infinity. Syntax: number.to_f Parameter: The function takes the integer which is to be converted to float. Return Value: The function returns the float value of the number. Example #1: # Ruby program for to_f function # Initializing t
1 min read
Ruby Integer to_i function with example
The to_i function in Ruby converts the value of the number to int. If the number itself is an int, it returns self only. Syntax: number.to_i Parameter: The function takes the number which is to be converted to int. Return Value: The function returns the int value. Example #1: # Ruby program for to_i function # Initializing the number num1 = 51 num2
1 min read
Ruby Integer to_r function with example
The to_r function in Ruby converts the value of the number to a rational. Syntax: number.to_r Parameter: The function takes the number which is to be converted to a rational number. Return Value: The function returns the rational number. Example #1: # Ruby program for to_r function # Initializing the number num1 = 51 num2 = 10.78 num3 = 1690.89 num
1 min read
Ruby Integer to_s function with example
The to_s function in Ruby returns a string containing the place-value representation of int with radix base (between 2 and 36). If no base is provided in the parameter then it assumes the base to be 10 and returns. Syntax: number.to_s(base) Parameter: The function takes the number and a base to which is to be converted. If no base is provided in th
1 min read
Ruby Integer truncate() function with example
The truncate() function in Ruby returns an int truncated value to a precision of ndigits decimal digits. When the precision is negative, the returned value is an integer with at least ndigits.abs trailing zeros. It returns itself when ndigits is zero or positive. The default value of ndigits is considered to be zero. Syntax: number.truncate(ndigits
1 min read
Ruby Integer prime? function with example
The prime? function in Ruby returns a boolean value. It returns true if the number is prime, else it returns false. It requires the 'prime' class to be pre-added. Syntax: number.prime? Parameter: The function takes the integer which is to be checked for prime or not. Return Value: The function returns a boolean value which determines if the value i
1 min read