Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以使用 Thor 操作从文件中删除一行文本。例如,我想删除 ruby 评论。到目前为止,我发现了 2 个操作:comment_lines- 注释掉行,以及gsub_file
comment_lines
gsub_file
谢谢
这对删除评论不起作用吗?
gsub_file(filename, /#.*$/, '')
编辑:
如果您想删除评论并删除仅包含评论信息的行,您可以尝试:
gsub_file(filename, /\S*#.*$/, '') # removes partial comments gsub_file(filename, /^\s*#.*\n/, '') # removes full line comments