On the following code, the third line errors with:
TypeError: can’t convert false into String
line = "some default text"
line << " some more text" unless more.empty?
line << (even_more.empty?) ? " done." : " and even more text"
What is a better way to do this?
Those parens are necessary because
<<has higher precedence than?(precedence table). Solution:As a side note, notice that you can take a functional approach when building arrays: