Ruby | Struct size() function
Last Updated :
06 Jan, 2020
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:
Places = Struct. new ( :name , :speciality )
detail = Places. new ( "Nagpur" , "oranges" )
puts detail.size
|
Output:
2
Example 2:
animals = Struct. new ( :name , :speciality , :found_in )
detail = animals. new ( "labrador" , "bark" , "Newfoundland" )
puts detail.size
|
Output:
3
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...