Last Updated: February 25, 2016
·
1.037K
· romulomachado

Update Ruby syntax on a Rails project (1.9.3 to 2.0.0)

To change all :foo => bar to foo: bar, just run:

$ find . -name \*.rb -exec perl -p -i -e 's/([^:]):(\w+)\s*=>/\1\2:/g' {} \;

UPDATE

@nicolaslazartekaqui warned me that the last command does not apply to the case {:foo? => bar} and suggested a little change to fix it, here it is:

$ find . -name \*.rb -exec perl -p -i -e 's/([^:]):(\w+?*)\s*=>/\1\2:/g' {} \;

Thanks, @nicolaslazartekaqui.

3 Responses
Add your response

not apply in this case {:foo? => bar}

little change in command to fix this

$ find . -name \*.rb -exec perl -p -i -e 's/([^:]):(\w+?*)\s*=>/\1\2:/g' {} \;
over 1 year ago ·

Thanks for the correction, @nicolaslazartekaqui. I'll update it.

over 1 year ago ·

For Sublime Text users, I like this utility: https://github.com/iltempo/sublime-text-2-hash-syntax

over 1 year ago ·