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 |
chevron_right
filter_none
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 |
chevron_right
filter_none
Output:
name imdbrating
Recommended Posts:
- Ruby Static Members
- Ruby | Struct to_s() function
- Ruby | Struct eql?() function
- Ruby | Struct values() function
- Ruby | Struct length() function
- Ruby | Struct size() function
- Ruby | Struct to_a() function
- Ruby | Struct values_at() function
- Ruby | Struct filter() function
- Ruby | Struct each() function
- Ruby | Struct == function
- Ruby | Struct inspect() function
- Ruby | Struct Class
- Ruby | Matrix cofactor() function
- Ruby Integer odd? function with example
- Ruby Integer div() function with example
- Ruby | Symbol to_s function
- Ruby | Set replace() function
- Ruby | Set reset() function
- Ruby | Array Concatenation using (+) function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

