The length() is an inbuilt method in Ruby that returns the number of members in struct.
Syntax: struct_name.length()
Parameters: The function does not accepts any parameter.
Return Value: It returns the number of members in the struct.
Example 1:
Student = Struct. new ( :name , :address , :dept )
detail = Student. new ( "Shizuka" , "Washington" , "CSE" )
puts detail.length
|
Output:
3
Example 2:
Student = Struct. new ( :name , :address , :dept , :project )
detail = Student. new ( "Vishwa" , "Hyderabad" , "CSE" , "IOT" )
puts detail.length
|
Output:
4
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
18 Dec, 2019
Like Article
Save Article