Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | Struct to_a() function

  • Last Updated : 21 Jan, 2021

The to_a() is an inbuilt method in Ruby that returns an array with the value of the particular struct.

Syntax: struct_name.to_a[integer]

Parameters: The function accepts an integer parameter which specifies the index of the struct value to be returned.

Return Value: It returns the value of struct. 

Example 1:  


# Ruby program for to_a  method in struct
# Include struct
animals =, :speciality , :found_in)
#initialize values
detail ="labrador", "bark" , "Newfoundland")
#print value 2
puts detail.to_a[2]  



Example 2


# Ruby program for to_a method in struct
# Include struct
place =, :speciality)
#initialize values
detail ="nagpur","orange")
#print value 1
puts detail.to_a[1]




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!