Module: Tallyit::DeleteTally

Defined in:
lib/tallyit/delete_tally.rb

Class Method Summary collapse

Class Method Details

.do(file, lineno) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/tallyit/delete_tally.rb', line 3

def self.do(file, lineno)
  File.open(file + '.tmp', 'w') do |tmp_file|
    File.open(file, 'r') do |file|
      file.each_with_index do |line, index|
        next if index + 1 == lineno
        tmp_file.puts line
      end
    end
  end
  `mv #{file + '.tmp'} #{file}`
end