在Ruby(而非Rails)中的else if条件中,检查变量是否不为空的最佳方法是什么?
elsif not variable.to_s.empty?
# do something
end
或者
elsif !variable.to_s.empty?
# do something
end
或者
elsif variable.to_s.length > 0
# do something
end
string = ""
unless string.to_s.strip.empty?
# ...
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句