📜  红宝石 |字符串为空?方法

📅  最后修改于: 2022-05-13 01:54:20.939000             🧑  作者: Mango

红宝石 |字符串为空?方法

空的?是 Ruby 中的 String 类方法,用于检查字符串长度是否为零。

示例 1:

# Ruby program to demonstrate
# the empty? method
   
# Taking a string and
# using the method
puts "checking".empty?
puts "method".empty?

输出:

false
false

示例 2:

# Ruby program to demonstrate
# the empty? method
   
# Taking a string and
# using the method
puts "".empty?
puts ".".empty?

输出:

true
false