Module: Extensions::File
- Defined in:
- lib/extensions/file.rb
Instance Method Summary collapse
Instance Method Details
#copylines(src, dst) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/extensions/file.rb', line 5 def copylines(src, dst) tempfile = Tempfile.new(dst) begin open(src).each_line do |line| if block_given? new_line = yield(line) line = new_line unless new_line.nil? end tempfile.write line end FileUtils.chmod(stat(src).mode, tempfile.path) FileUtils.move(tempfile.path, dst) ensure tempfile.close! end end |