Symbol#=~():=~() 是一個 Symbol 類方法,它=~用符號表示模式。
用法:Symbol.=~()
參數:符號值
Return: 位置 - 如果模式 =~ 符號,否則返回 nil
示例#1:
# Ruby code for Symbol.=~() 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"
# =~ form
puts "Symbol a =~ form : #{a.=~(/D/)}\n\n"
puts "Symbol b =~ form : #{b.=~(/o/)}\n\n"
puts "Symbol c =~ form : #{c.=~(/C/)}\n\n"
輸出:
Symbol a : aBcDeF Symbol b : äöü Symbol c : ABCDEF Symbol a =~ form : 3 Symbol b =~ form : Symbol c =~ form : 2
示例#2:
# Ruby code for Symbol.=~() 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"
# =~ form
puts "Symbol a =~ form : #{a.=~(/g/)}\n\n"
puts "Symbol b =~ form : #{b.=~(/a/)}\n\n"
puts "Symbol c =~ form : #{c.=~(/EE/)}\n\n"
輸出:
Symbol a : geeks Symbol b : åöó Symbol c : GEEKS Symbol a =~ form : 0 Symbol b =~ form : Symbol c =~ form : 1
相關用法
- Scala Symbol ==用法及代碼示例
- Scala Symbol ===用法及代碼示例
- Scala Symbol.on用法及代碼示例
- Scala Symbol.orElse用法及代碼示例
- Scala Symbol.orElseBy用法及代碼示例
- Scala SymbolOrdering.on用法及代碼示例
- Scala SymbolOrdering.orElseBy用法及代碼示例
- Scala SymbolOrdering.orElse用法及代碼示例
- Scala SymbolModule.spliceOwner用法及代碼示例
- Scala SystemProperties.partitionMap用法及代碼示例
- Scala SystemProperties.unzip用法及代碼示例
- Scala SystemProperties.mkString用法及代碼示例
- Scala SystemProperties.groupMap用法及代碼示例
- Scala SystemProperties.sizeCompare用法及代碼示例
- Scala SystemProperties.inits用法及代碼示例
- Scala SystemProperties.addString用法及代碼示例
- Scala SystemProperties.scanRight用法及代碼示例
- Scala SystemProperties.elementWise用法及代碼示例
- Scala SystemProperties.runWith用法及代碼示例
- Scala SystemProperties.tails用法及代碼示例
- Scala SystemProperties.groupBy用法及代碼示例
- Scala SystemProperties.transpose用法及代碼示例
- Scala SystemProperties.equals用法及代碼示例
- Scala SystemProperties.sliding用法及代碼示例
- Scala SystemProperties.sizeIs用法及代碼示例
注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby | Symbol =~ function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。