📜  红宝石 |符号 casecmp函数

📅  最后修改于: 2022-05-13 01:54:40.551000             🧑  作者: Mango

红宝石 |符号 casecmp函数

Symbol#casecmp() : casecmp()是一个 Symbol 类方法,用于检查 Symbol 的大小写不敏感版本

示例 #1:

# Ruby code for Symbol.casecmp() method
  
# declaring Symbol 
a = :aBcDeF
  
# declaring Symbol
b = :"\u{e4 f6 fc}"
  
# declaring Symbol
c = :ABCDEF
  
# Symbol 
puts "Symbol a : #{a}\n\n"
puts "Symbol b : #{b}\n\n"
puts "Symbol c : #{c}\n\n\n\n"
  
  
# casecmp form 
puts "Symbol a casecmp form : #{a.casecmp(:aBcDeF)}\n\n"
puts "Symbol b casecmp form : #{b.casecmp(:"\u{e4 f6 fc}")}\n\n"
puts "Symbol c casecmp form : #{c.casecmp(:abcd)}\n\n"

输出 :

Symbol a : aBcDeF

Symbol b : äöü

Symbol c : ABCDEF



Symbol a casecmp form : 0

Symbol b casecmp form : 0

Symbol c casecmp form : 1

示例 #2:

# Ruby code for Symbol.casecmp() method
  
# declaring Symbol 
a = :geeks
  
# declaring Symbol
b = :"\u{e5 f6 f3}"
  
# declaring Symbol
c = :GEEKS
  
# Symbol 
puts "Symbol a : #{a}\n\n"
puts "Symbol b : #{b}\n\n"
puts "Symbol c : #{c}\n\n\n\n"
  
  
# casecmp form 
puts "Symbol a casecmp form : #{a.casecmp(:gEEks)}\n\n"
puts "Symbol b casecmp form : #{b.casecmp(:"\u{e5 f6 f3}")}\n\n"
puts "Symbol c casecmp form : #{c.casecmp(:GGGG)}\n\n"

输出 :

Symbol a : geeks

Symbol b : åöó

Symbol c : GEEKS



Symbol a casecmp form : 0

Symbol b casecmp form : 0

Symbol c casecmp form : -1