Ruby | Integer upto() function Last Updated : 04 Dec, 2020 Comments Improve Suggest changes Like Article Like Report The upto function in Ruby returns all the numbers from a given to number itself. It iterates the given block, passing in increasing values from number1 up to number2. If no block is given, an Enumerator is returned instead. Syntax: (number1).upto(number2) Parameter: The function takes number1 and number2 which is the range in which the numbers are returned. It also takes a block. Return Value: The function returns all the numbers from number1 to number2 itself. Example 1: Ruby #Ruby program for upto() function #Initializing the number num1 = 8 num2 = 12 #Prints the number from num1 to num2 puts num1.upto(num2) { | i | print i, " " } #Initializing the number num3 = 5 num4 = 15 #Prints the number from num3 to num4 puts num3.upto(num4) { | i | print i, " " } Output: 8 9 10 11 12 8 5 6 7 8 9 10 11 12 13 14 15 5 Example 2: Ruby #Ruby program for upto() function #Initializing the number num1 = 1 num2 = 3 #Prints the number from num1 to num2 puts num1.upto(num2) { | i | print i, " " } #Initializing the number num3 = -7 num4 = -2 #Prints the number from num3 to num4 puts num3.upto(num4) { | i | print i, " " } Output: 1 2 3 1 -7 -6 -5 -4 -3 -2 -7 Example 3: Ruby #Ruby program for upto() function #Initializing the number num1 = 1 num2 = 3 #Returns an enumerator #since no block is passed puts num1.upto(num2) Output: # Reference: https://devdocs.io/ruby~2.5/integer#method-i-upto Comment More infoAdvertise with us Next Article Ruby | Integer upto() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Integer-class Similar Reads Ruby | Integer - function The - is an inbuilt method in Ruby returns the subtraction of two numbers. It returns num1 - num2. Syntax: num1 - num2 Parameters: The function accepts no parameter. Return Value: It returns the subtraction of two numbers. Example 1: Ruby # Ruby program for - method in Integer # Initialize numbers n 1 min read Ruby | Integer sqrt() function The sqrt() function in Ruby returns the integer square root of the non-negative integer n, i.e. the largest non-negative integer less than or equal to the square root of n Syntax: Integer.sqrt(number) Parameter: The function takes the integer whose square root is to be returned. It throws an error " 1 min read Ruby | Integer >= function The >= is an inbuilt method in Ruby returns true if the number is greater than or equal to the given number, else it returns false. Syntax: num1 >= num2 Parameters: The function accepts no parameter. Return Value: It returns true if the number is greater than or equal to the given number, else 1 min read Ruby | Numeric to_int() function The to_int() is an inbuilt method in Ruby returns the integer part of the given number. Syntax: num.to_int() Parameters: The function needs the number whose integer part is to be returned. Return Value: It returns the integer part. Example 1: Ruby # Ruby program for to_int() # method in Numeric # In 1 min read Ruby | Range to_a() function The to_a() is an inbuilt method in Ruby returns an array containing the numbers in the given range. Syntax: range1.to_a() Parameters: The function accepts no parameter. Return Value: It returns an array containing all the numbers. Example 1: Ruby # Ruby program for to_a() # method in Range # Initial 1 min read Like