红宝石 |符号大小函数
Symbol#size() : size()是一个 Symbol 类方法,它返回符号对象的大小/长度。
Syntax: Symbol.size()
Parameter: Symbol values
Return: the size/length of the symbol object.
示例 #1:
# Ruby code for Symbol.size() 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"
# size form
puts "Symbol a size form : #{a.size}\n\n"
puts "Symbol b size form : #{b.size}\n\n"
puts "Symbol c size form : #{c.size}\n\n"
输出 :
Symbol a : aBcDeF
Symbol b : äöü
Symbol c : ABCDEF
Symbol a size form : 6
Symbol b size form : 3
Symbol c size form : 6
示例 #2:
# Ruby code for Symbol.size() 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"
# size form
puts "Symbol a size form : #{a.size}\n\n"
puts "Symbol b size form : #{b.size}\n\n"
puts "Symbol c size form : #{c.size}\n\n"
输出 :
Symbol a : geeks
Symbol b : åöó
Symbol c : GEEKS
Symbol a size form : 5
Symbol b size form : 3
Symbol c size form : 5