Symbol#casecmp():casecmp()是一個Symbol類方法,用於檢查Symbol的大小寫敏感版本
用法:Symbol.casecmp()
參數:符號值
返回:大小寫敏感版本的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
相關用法
- Scala Symbol =~用法及代碼示例
- Ruby Symbol next用法及代碼示例
- Scala Symbol ==用法及代碼示例
- Scala Symbol ===用法及代碼示例
- Ruby String casecmp?用法及代碼示例
- Ruby String casecmp用法及代碼示例
- Ruby Symbol match用法及代碼示例
- Ruby Symbol length用法及代碼示例
- Ruby Symbol intern用法及代碼示例
- Ruby Symbol size用法及代碼示例
- Ruby Symbol slice用法及代碼示例
- Ruby Symbol succ用法及代碼示例
- Ruby Symbol swapcase用法及代碼示例
- Ruby Symbol to_proc用法及代碼示例
- Ruby Symbol to_sym用法及代碼示例
注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby | Symbol casecmp function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。