Ruby | Range to_a() function Last Updated : 19 Mar, 2024 Improve Improve Like Article Like Save Share Report 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 program for to_a() # method in Range # Initialize range range1 = (0..4) # Prints the array puts range1.to_a() Output: 0 1 2 3 4 Example 2: # Ruby program for to_a() # method in Range # Initialize range range1 = (7..9) # Prints the array puts range1.to_a() Output: 7 8 9 Like Article Suggest improvement Previous Ruby | clear() function Next Ruby | Range to_s() function Share your thoughts in the comments Add Your Comment Please Login to comment...