The length() is an inbuilt method in Ruby that returns the number of members in struct.
Syntax: struct_name.length()
Parameters: The function does not accepts any parameter.
Return Value: It returns the number of members in the struct.
Example 1:
# Ruby program for length method in struct # Include struct Student = Struct.new(:name, :address, :dept) # initialize values detail = Student.new("Shizuka", "Washington", "CSE") # length used puts detail.length |
chevron_right
filter_none
Output:
3
Example 2:
# Ruby program for length method in struct # Include struct Student = Struct.new(:name, :address, :dept , :project) # initialize values detail = Student.new("Vishwa", "Hyderabad", "CSE" , "IOT") # length used puts detail.length |
chevron_right
filter_none
Output:
4
Recommended Posts:
- Ruby | Struct to_s() function
- Ruby | Struct eql?() function
- Ruby | Struct values() function
- Ruby | Struct members() 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 | SizedQueue length() function
- Ruby | Queue length() function
- Ruby | Set length() function
- Ruby | Symbol length function
- Ruby | Array length() function
- Ruby | String length Method
- Ruby | Hash length() method
- Ruby | Matrix cofactor() 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.

