Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deleting a line in a file using Thor

Is it possible using Thor actions to delete a line(s) of text from a file. For example I would like to delete ruby comments. So far I have found 2 actions: comment_lines - which comments out lines, and gsub_file

Thanks

like image 713
user1740206 Avatar asked Dec 12 '25 05:12

user1740206


1 Answers

Does this not work to remove comments?

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

Edit:

If you want to remove comments and delete lines with only comment information, you could try:

gsub_file(filename, /\S*#.*$/, '')   # removes partial comments
gsub_file(filename, /^\s*#.*\n/, '') # removes full line comments
like image 164
psugar Avatar answered Dec 14 '25 21:12

psugar