Top Level Namespace

Defined Under Namespace

Modules: Vagrant Classes: DnsmasqConf, Domain, Ip, Object, Resolver

Instance Method Summary collapse

Instance Method Details

#delete_line_from_file(filename, line) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/vagrant-dnsmasq/includes/helper.rb', line 1

def delete_line_from_file(filename, line)
  # create empty file string
  tmp_file = ''

  # iterate over every line and skip lines that match
  File.open(filename, "r").each_line do |l|
    tmp_file += l unless line.match(l.strip)
  end

  # write tmp file without matching lines
  File.open(filename, 'w') { |file| file.write tmp_file }

  # clear memory
  tmp_file = nil
end