Open In App

Ruby | Struct size() function

Last Updated : 06 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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
# 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 
Output:
2
Example 2: Ruby
# 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 
Output:
3

Next Article

Similar Reads