红宝石 |符号切片函数
Symbol#slice() : slice()是一个 Symbol 类方法,它对符号对象进行切片并返回字符值。
Syntax: Symbol.slice()
Parameter: Symbol values
Return: slices the symbol object and return the character value.
示例 #1:
# Ruby code for Symbol.slice() 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"
# slice form
puts "Symbol a slice form : #{a.slice(1)}\n\n"
puts "Symbol b slice form : #{b.slice(1)}\n\n"
puts "Symbol c slice form : #{c.slice(3)}\n\n"
输出 :
Symbol a : aBcDeF
Symbol b : äöü
Symbol c : ABCDEF
Symbol a slice form : B
Symbol b slice form : ö
Symbol c slice form : D
示例 #2:
# Ruby code for Symbol.slice() 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"
# slice form
puts "Symbol a slice form : #{a.slice(1)}\n\n"
puts "Symbol b slice form : #{b.slice(1)}\n\n"
puts "Symbol c slice form : #{c.slice(3)}\n\n"
输出 :
Symbol a : geeks
Symbol b : åöó
Symbol c : GEEKS
Symbol a slice form : e
Symbol b slice form : ö
Symbol c slice form : K