Ruby Integer times function with example Last Updated : 17 Mar, 2020 Comments Improve Suggest changes Like Article Like Report 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 an block. Return Value: The function returns all the numbers from 0 to one less than the number itself. Example #1: Ruby # Ruby program for times function # Initializing the number num1 = 8 # Prints the number from 0 to num1-1 puts num1.times { |i| print i, " " } # Initializing the number num2 = 5 # Prints the number from 0 to num2-1 puts num2.times { |i| print i, " " } Output : 0 1 2 3 4 5 6 7 0 1 2 3 4 Example #2: Ruby # Ruby program for times function # Initializing the number num1 = 4 # Prints the number from 0 to num1-1 puts num1.times { |i| print i, " " } # Initializing the number num2 = -2 # Prints the number from 0 to num2 puts num2.times { |i| print i, " " } Output: 0 1 2 3 -2 Example #3: Ruby # Ruby program for times function # Initializing the number num1 = 5 # Prints enumerator as no block is given puts num1.times Output: # Comment More infoAdvertise with us Next Article Ruby Integer times function with example G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Integer-class Similar Reads Ruby Integer size() function with example The size() function in Ruby returns the number of bytes in the machine representation of int. Syntax: number.size Parameter: The function takes the integer whose number of bytes is returned. Return Value: The function returns the number of bytes. Example #1: Ruby # Ruby program for size() function # 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 # Ruby program for to_r function # Initializi 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 # Ruby program for 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: 1 min read Ruby Integer to_int function with example The to_int function in Ruby converts the value of the number to int. If the number itself is an int, it returns self only. It is an alias of to_i function. Syntax: number.to_int Parameter: The function takes the number which is to be converted to int. Return Value: The function returns the int valu 1 min read Like