I have a multiline string array via percent string like this:
array = %w(test
foo
bar)
I want to add a comment message to the foo
entry, something like
array = %w(test
# TODO: Remove this line after fix #1
foo
bar)
Is there any way to do it without converting it to basic array like this?
array = ['test',
# TODO: Remove this line after fix #1
'foo',
'bar']
I think there is no way to make that work, because %w()
evaluates every space delimited element inside it to string.
There's no way from inside the string to make Ruby evaluate that string.
The only and tricky way:
array = %W(test
#@foo
bar).reject(&:empty?)
Note capital W
and reject
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With