empty?()是Ruby中的內置方法,如果集合為空或返回false,則返回true。
用法:s1.empty?()
參數:該函數不帶任何參數。
返回值:它返回一個布爾值。如果集合為空,則返回true,否則返回false。
例子1:
# Ruby program to illustrate the empty method
# requires the set
require "set"
s1 = Set[]
# empty method used
puts "is empty?:"
puts s1.empty?()
輸出:
is empty?:
true
例子2:
# Ruby program to illustrate the empty method
# requires the set
require "set"
s1 = Set[16, 8, 3, 5, 2]
# empty method used
puts "is empty?:"
puts s1.empty?()
輸出:
false
相關用法
- Ruby StringScanner empty?用法及代碼示例
- Ruby SizedQueue empty?用法及代碼示例
- Ruby Matrix empty?()用法及代碼示例
- Ruby Symbol empty?用法及代碼示例
- Ruby Hash empty?用法及代碼示例
- Ruby Queue empty?用法及代碼示例
- Ruby String empty?用法及代碼示例
- Ruby Array class empty?()用法及代碼示例
- Ruby Set add?用法及代碼示例
- Ruby Time now()用法及代碼示例
- Ruby Math log()用法及代碼示例
- Ruby Math exp()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Set empty?() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。