Skip to content

Instantly share code, notes, and snippets.

@elvuel
Created January 2, 2014 06:13
Show Gist options
  • Save elvuel/8215646 to your computer and use it in GitHub Desktop.
Save elvuel/8215646 to your computer and use it in GitHub Desktop.
rails app simple rename
# encoding: utf-8
args = ARGV.dup
from = args.first || "name"
to = args.last || "to"
cmd = "find ./ -name \"*.rb\" | xargs grep #{from}"
result = `#{cmd}`
files = result.split("\n").map { |l| l.split(":").first }
# files.pop if ARGV.first == "i"
files.each do |file|
result = File.open(file, 'r') { |f| f.read }
result.gsub!(from, to)
File.open(file, 'w') { |f| f.write result }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment