Ruby | Struct length() function
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 structStudent = Struct.new(:name, :address, :dept) # initialize valuesdetail = Student.new("Shizuka", "Washington", "CSE") # length usedputs detail.length |
Output:
3
Example 2:
# Ruby program for length method in struct # Include structStudent = Struct.new(:name, :address, :dept , :project) # initialize valuesdetail = Student.new("Vishwa", "Hyderabad", "CSE" , "IOT") # length usedputs detail.length |
Output:
4



