Open In App
Related Articles

Ruby | Range to_a() function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
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

Last Updated : 06 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads