compare_by_identity?()是Ruby中的一個內置方法,如果該集合將通過元素的身份比較其元素,則返回true。
用法:s1.name.compare_by_identity?()
參數:該函數不帶任何參數。
返回值:如果集合將通過其元素比較其元素,則返回true。
例子1:
#Ruby program to illustrate the 
#compare_by_identity ? method 
  
#requires the set 
require "set"
  
    s1 
    = Set[] 
  
      puts s1.compare_by_identity 
    ? () 
  
#Add 10 to it 
              s1 
          << 10 
  
             puts s1.compare_by_identity 
    ? () 
  
              s1 
          << 'a'
  
             puts s1.compare_by_identity 
    ? ()輸出:
false false false
例子2:
#Ruby program to illustrate the 
#compare_by_identity ? method 
  
#requires the set 
require "set"
  
    s1 
    = Set[1, 2, 3] 
  
      puts s1.compare_by_identity 
    ? () 
  
#Add 12 to it 
              s1 
          << 12 
  
             puts s1.compare_by_identity 
    ? ()輸出:
false false
參考:https://devdocs.io/ruby~2.5/set#method-i-compare_by_identity-3F
相關用法
- Ruby Set add?用法及代碼示例
- Ruby Set empty?()用法及代碼示例
- Ruby Range new()用法及代碼示例
- Ruby Hash eql?用法及代碼示例
- Scala Integer -用法及代碼示例
- Ruby Integer abs()用法及代碼示例
- Ruby Hash dig()用法及代碼示例
- Ruby Hash each()用法及代碼示例
- Ruby Range first()用法及代碼示例
- Ruby Range last()用法及代碼示例
- Ruby Integer chr用法及代碼示例
- Ruby Enumerable any?用法及代碼示例
- Ruby Enumerable max()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Set compare_by_identity? function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
