Open In App

Ruby | Struct size() function

Last Updated : 06 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
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 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 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

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads