Ruby 符号 empty? 函数
Symbol#empty?() : empty?() 是Symbol类的一个方法,用于检查符号是否为空。
语法。符号.empty?()
参数。符号值
返回:true – 如果符号是空的,否则返回false
例子 #1 :
# Ruby code for Symbol.empty?() 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"
# empty? form
puts "Symbol a empty? form : #{a.empty?}\n\n"
puts "Symbol b empty? form : #{b.empty?}\n\n"
puts "Symbol c empty? form : #{c.empty?}\n\n"
输出:
Symbol a : aBcDeF
Symbol b : äöü
Symbol c : ABCDEF
Symbol a empty? form : false
Symbol b empty? form : false
Symbol c empty? form : false
例子 #2 :
# Ruby code for Symbol.empty?() method
# declaring Symbol
a = :geeks
# declaring Symbol
b = :"\u{e5 f6 f3}"
# declaring Symbol
c = ""
# Symbol
puts "Symbol a : #{a}\n\n"
puts "Symbol b : #{b}\n\n"
puts "Symbol c : #{c}\n\n\n\n"
# empty? form
puts "Symbol a empty? form : #{a.empty?}\n\n"
puts "Symbol b empty? form : #{b.empty?}\n\n"
puts "Symbol c empty? form : #{c.empty?}\n\n"
输出:
Symbol a : geeks
Symbol b : åöó
Symbol c :
Symbol a empty? form : false
Symbol b empty? form : false
Symbol c empty? form : true