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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
