length()是Ruby中的內置方法,該方法返回struct中的成員數。
用法: struct_name.length()
參數:該函數不接受任何參數。
返回值:返回結構中的成員數。
例子1:
# 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
輸出:
3
例子2:
# 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
輸出:
4
相關用法
- Scala Struct ==用法及代碼示例
- Ruby Struct eql?()用法及代碼示例
- Ruby Struct each()用法及代碼示例
- Ruby Struct filter()用法及代碼示例
- Ruby Struct to_s()用法及代碼示例
- Ruby Struct values_at()用法及代碼示例
- Ruby Struct to_a()用法及代碼示例
- Ruby Struct members()用法及代碼示例
- Ruby Struct values()用法及代碼示例
- Ruby Struct inspect()用法及代碼示例
- Ruby Struct size()用法及代碼示例
- Ruby Set length()用法及代碼示例
- Ruby Queue length()用法及代碼示例
- Ruby Symbol length用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Struct length() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。