Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class String
def starts_with?(prefix)
prefix.respond_to?(:to_str) && self[0, prefix.length] == prefix
end
end
def delete_lines_from_file(filename)
line_arr = File.readlines(filename)
line_arr.delete_at(0)
line_arr.delete_at(0) if line_arr.first == "\n"
File.open(filename, "w") do |f|
line_arr.each{|line| f.puts(line)}
end
end
def remove_encoding_head(filename)
if File.new(filename).gets.strip == '# coding: UTF-8'
delete_lines_from_file(filename)
end
end
ruby_files = Dir.glob('/home/lvargas/projects/emergia/**/*.rb').select{ |e| File.file?(e) }
ruby_files.each do |filename|
remove_encoding_head(filename)
end
p 'Remove enconding head has finished'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment