Ruby | Struct size() function
Last Updated :
06 Jan, 2020
Improve
The size() is an inbuilt method in Ruby that returns the total number of members present in struct.
Ruby
Output:
Ruby
Output:
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 struct
Places = Struct.new(:name, :speciality)
#initialize values
detail = Places.new("Nagpur", "oranges")
# size used
puts detail.size
2Example 2:
# Ruby program for size method in struct
# Include struct
animals = Struct.new(:name, :speciality , :found_in)
# initialize values
detail = animals.new("labrador", "bark" , "Newfoundland")
# size used
puts detail.size
3