I have 4 string variables name, quest, favorite_color, speed
that might be empty. I want to concatenate them all together, putting spaces between those that aren't empty. Simplicity of the code, i.e how simple is to to look at and understand, is more important than speed.
So:
name = 'Tim'
quest = 'destroy'
favorite_color = 'red'
speed = 'fast'
becomes
'Tim destroy red fast'
and
name = 'Steve'
quest = ''
favorite_color = ''
speed = 'slow'
becomes:
'Steve slow'
Note there is only 1 space between 'Steve' and 'slow'.
How do I do that (preferably in 1 line)?
question from:
https://stackoverflow.com/questions/2434885/ruby-concatenate-strings-and-add-spaces 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…