Convert Ruby 1.8 to 1.9 Hash Syntax

Dan Croak

In Vim, for an entire file:

:%s/:\([^ ]*\)\(\s*\)=>/\1:/g

In the shell, for an entire project:

perl -pi -e 's/(?<![:]):([\w\d_]+)(\s*)=>/\1:/g' **/*.rb

Now, instead of those old-school hashes like this:

get "/", :agent => MOBILE_BROWSERS do

You’ll have new-school hashes like this:

get "/", agent: MOBILE_BROWSERS do

About thoughtbot

We've been helping engineering teams deliver exceptional products for over 20 years. Our designers, developers, and product managers work closely with teams to solve your toughest software challenges through collaborative design and development. Learn more about us.