Open In App

Ruby | Struct values() function

Improve
Improve
Like Article
Like
Save
Share
Report

The values() 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 struct value to be returned.

Return Value: It returns the value of struct.

Example 1:




# Ruby program for values method in struct 
    
# Include struct
place = Struct.new(:name, :speciality)
  
# initialize values
detail = place.new("nagpur","orange")
  
# print value 
puts detail.values  


Output:

nagpur
orange

Example 2:




# Ruby program for values method in struct 
    
# Include struct
animals = Struct.new(:name, :speciality , :found_in)
  
# initialize values
detail = animals.new("labrador", "bark" , "Newfoundland")
  
# values used
puts detail.values 


Output:

labrador
bark
Newfoundland

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