Skip to content
Related Articles

Related Articles

Ruby | Struct members() function
  • Last Updated : 06 Jan, 2020

The members() is an inbuilt method in Ruby that returns an array of symbols containing the struct members.

Syntax: struct_name.members()

Parameters: The function does not accepts any parameter.

Return Value: It returns the array with struct members.

Example 1:






# Ruby program for members method in struct 
    
# Include struct
Student = Struct.new(:name, :address, :dept , :project)
  
#initialize values
detail = Student.new("Vishwa", "Hyderabad", "CSE" , "IOT")
  
# members used
puts detail.members  

Output:

name
address
dept
project

Example 2:




# Ruby program for members method in struct 
    
# Include struct
Movie = Struct.new(:name, :imdbrating)
  
# initialize values
detail = Movie.new("3idiots", 5)
  
# members used
puts detail.members  

Output:

name
imdbrating
My Personal Notes arrow_drop_up
Recommended Articles
Page :