Skip to content

Instantly share code, notes, and snippets.

@jacknoble
Created June 1, 2017 20:30
Show Gist options
  • Save jacknoble/d03b2b6c519d1c1f32305267926d133b to your computer and use it in GitHub Desktop.
Save jacknoble/d03b2b6c519d1c1f32305267926d133b to your computer and use it in GitHub Desktop.
TRY_REGEX = /\.try!?\((?<args>.*?)\)/
Dir.glob("app/**/*{.rb,.erb,.jbuilder}").each do |fname|
text = File.open(fname, 'rb', &:read)
new_text = text.gsub(TRY_REGEX) do
(method_name, *args) = Regexp.last_match[:args].tr(' ', '').split(',')
if args.any?
"&#{method_name.tr(':', '.')}(#{args.join(', ')})"
else
"&#{method_name.tr(':', '.')}"
end
end
File.open(fname, 'w') { |f| f.write(new_text) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment