Skip to content

Instantly share code, notes, and snippets.

@gentooboontoo
Last active December 14, 2015 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gentooboontoo/5154258 to your computer and use it in GitHub Desktop.
Save gentooboontoo/5154258 to your computer and use it in GitHub Desktop.
Insert missing utf-8 encoding magic comment to existing ruby files. USAGE: ruby insert-utf8-encoding.rb <dir>
#!/usr/bin/env ruby
# encoding: utf-8
Dir[File.join(ARGV[0], '**', '*.{rb,rake}')].each do |file|
lines = File.open(file).readlines
next if lines[0].match(/#\s+(?:en)?coding:\s+utf-8/i)
puts "Adding encoding magic comment to #{file}"
File.open(file, 'w') do |io|
io << "# encoding: utf-8\n\n"
io << lines.join
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment