Add comment to line in multiline% w in ruby

I have a multi-line array of strings through a percentage string, for example:

array = %w(test
           foo
           bar)

I want to add a comment to the post foo, something like

array = %w(test
           # TODO: Remove this line after fix #1
           foo
           bar)

Is there a way to do this without converting it to a base array as follows?

array = ['test',
         # TODO: Remove this line after fix #1
         'foo',
         'bar']
+4
source share
2 answers

I think that there is no way to do this work, because it %w()evaluates each element with a spatial constraint inside it in a row.

There is no way inside a line to get Ruby to evaluate this line.

+2
source

The only and tricky way:

array = %W(test
           #@foo
           bar).reject(&:empty?)

Note: capital Wandreject

-1
source

Source: https://habr.com/ru/post/1655634/


All Articles