Ruby | Range to_a() function
Last Updated :
19 Mar, 2024
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:
range1 = ( 0 .. 4 )
puts range1.to_a()
|
Output:
0
1
2
3
4
Example 2:
range1 = ( 7 .. 9 )
puts range1.to_a()
|
Output:
7
8
9
Share your thoughts in the comments
Please Login to comment...