Created
July 15, 2012 21:14
-
-
Save razenha/3118663 to your computer and use it in GitHub Desktop.
A small ruby script that checks if all the .rb files in the given project starts with "# encoding: utf-8"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
class String | |
def starts_with?(prefix) | |
prefix = prefix.to_s | |
self[0, prefix.length] == prefix | |
end | |
end | |
all_files = Dir["./**/*.rb"] | |
all_files.each do |file| | |
begin | |
first_line = File.open file, &:readline | |
if !first_line.starts_with? "# encoding: utf-8" | |
puts file | |
content = File.readlines(file) | |
content.insert(0, "# encoding: utf-8\n") | |
File.open(file, "w") { |f| | |
content.each { |line| | |
f << line | |
} | |
} | |
# return 0 | |
end | |
rescue | |
puts "Erro ao ler file: #{file}" | |
raise $! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment