pathname: add append_lines method
* Blocks writing of new files via accidental typos, etc, which the normal open("blah", "a") doesn't.
* Where files don't exist they should ideally be using `(buildpath/"dog").write` instead of open("blah", "a") already.
* It's a bit less cluttered looking if you need several writes to different files in the formula, IMO.
This commit is contained in:
parent
7c9dff1f1e
commit
ff4d16deeb
@ -131,6 +131,12 @@ class Pathname
|
||||
open("w", *open_args) { |f| f.write(content) }
|
||||
end
|
||||
|
||||
# Only appends to a file that is already created.
|
||||
def append_lines(content, *open_args)
|
||||
raise "Cannot append file that doesn't exist: #{self}" unless exist?
|
||||
open("a", *open_args) { |f| f.puts(content) }
|
||||
end
|
||||
|
||||
def binwrite(contents, *open_args)
|
||||
open("wb", *open_args) { |f| f.write(contents) }
|
||||
end unless method_defined?(:binwrite)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user