Open In App
Related Articles

Ruby | Enumerable to_a() function

Improve Article
Improve
Save Article
Save
Like Article
Like

The to_a() of enumerable is an inbuilt method in Ruby returns an array containing all the items of the enumerable.

Syntax: enu.to_a()

Parameters: The function does not accepts any parameter.

Return Value: It returns an array.

Example #1:




# Ruby program for to_a method in Enumerable
  
# Initialize 
enu = (1..6)
  
# Prints 
enu.to_a

Output:

[1, 2, 3, 4, 5, 6]

Example #2:




# Ruby program for to_a method in Enumerable
  
# Initialize 
enu = {"gopal"=>10, "geeks"=>20}
  
# Prints 
enu.to_a

Output:

[["gopal", 10], ["geeks", 20]]
Last Updated : 05 Dec, 2019
Like Article
Save Article
Similar Reads