在以下代码中,第三行错误:
TypeError:无法将false转换为String
TypeError:无法将false转换为String
line = "some default text" line << " some more text" unless more.empty? line << (even_more.empty?) ? " done." : " and even more text"
有什么更好的方法呢?
解决方法
那些parens是必要的,因为<<优先级高于? (
precedence table).解:
line << (even_more.empty? ? " done." : " and even more text")
line = [ "some default text",("some more text" unless more.empty?),even_more.empty? ? "done." : "and even more text",].compact.join(" ")