Deleting a line in a file with Thor

Is it possible to use Thor actions to remove line (s) of text from a file. For example, I would like to remove ruby ​​comments. So far I have found 2 actions: comment_lines

- which selects lines andgsub_file

thank

+3


source to share


1 answer


Doesn't this work for deleting comments?

gsub_file(filename, /#.*$/, '') 

      

Edit:



If you want to remove comments and remove lines with only comments, you can try:

gsub_file(filename, /\S*#.*$/, '')   # removes partial comments
gsub_file(filename, /^\s*#.*\n/, '') # removes full line comments

      

+5


source







All Articles