[英]deleting a line in a file using Thor
Is it possible using Thor actions to delete a line(s) of text from a file. 是否可以使用Thor操作从文件中删除一行文本。 For example I would like to delete ruby comments. 例如,我想删除ruby评论。 So far I have found 2 actions: comment_lines
- which comments out lines, and gsub_file
到目前为止,我已经找到了2个动作: comment_lines
- 注释掉行和gsub_file
Thanks 谢谢
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.