Ruby 符号 size函数
Symbol#size() : size() 是 Symbol 类的一个方法,用于返回符号对象的大小/长度。
语法。Symbol.size()
参数。符号值
返回:符号对象的大小/长度。
例子 #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