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:
Student = Struct. new ( :name , :address , :dept , :project )
detail = Student. new ( "Vishwa" , "Hyderabad" , "CSE" , "IOT" )
puts detail.members
|
Output:
name
address
dept
project
Example 2:
Movie = Struct. new ( :name , :imdbrating )
detail = Movie. new ( "3idiots" , 5 )
puts detail.members
|
Output:
name
imdbrating