Ruby | Struct size() function
The size() is an inbuilt method in Ruby that returns the total number of members present in struct.
Syntax: struct_name.size()
Parameters: The function does not accepts any parameter.
Return Value: It returns the integer specifying the members of struct.
Example 1:
# Ruby program for size method in struct # Include structPlaces = Struct.new(:name, :speciality) #initialize valuesdetail = Places.new("Nagpur", "oranges") # size usedputs detail.size |
Output:
2
Example 2:
# Ruby program for size method in struct # Include structanimals = Struct.new(:name, :speciality , :found_in) # initialize valuesdetail = animals.new("labrador", "bark" , "Newfoundland") # size usedputs detail.size |
Output:
3



