Method: Thor::Actions#comment_lines
- Defined in:
- lib/thor/actions/file_manipulation.rb
#comment_lines(path, flag, *args) ⇒ Object
Comment all lines matching a given regex. It will leave the space which existed before the beginning of the line in tact and will insert a single space after the comment hash.
Parameters
- path<String>
-
path of the file to be changed
- flag<Regexp|String>
-
the regexp or string used to decide which lines to comment
- config<Hash>
-
give :verbose => false to not log the status.
Example
comment_lines 'config/initializers/session_store.rb', /cookie_store/
308 309 310 311 312 |
# File 'lib/thor/actions/file_manipulation.rb', line 308 def comment_lines(path, flag, *args) flag = flag.respond_to?(:source) ? flag.source : flag gsub_file(path, /^(\s*)([^#\n]*#{flag})/, '\1# \2', *args) end |