Open In App

Ruby | Struct length() function

Last Updated : 18 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
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: Ruby
# Ruby program for length method in struct 
  
# Include struct
Student = Struct.new(:name, :address, :dept)

# initialize values
detail = Student.new("Shizuka", "Washington", "CSE")

# length used
puts detail.length  
Output:
3
Example 2: Ruby
# Ruby program for length method in struct 
  
# Include struct
Student = Struct.new(:name, :address, :dept , :project)

# initialize values
detail = Student.new("Vishwa", "Hyderabad", "CSE" , "IOT")

# length used
puts detail.length  
Output:
4

Next Article

Similar Reads