Last Updated: February 25, 2016
·
1.534K
· Marko Klemetti

Upgrade your Ruby hashes to 1.9 with Sublime

In Ruby 1.8 the hashes use syntax a => b. This was upgraded to the json-like format a: b for Ruby 1.9 (while the old format is still supported).

Since the JSON-format is easier to read and follows current standards, I encourage you to start upgrading while you make changes in your old codebase. See the very simple step-by-step guide below:

  1. Open your project in Sublime (or any other editor supporting regex search-and-replace)
  2. Select Replace... or press Alt-Cmd-F
  3. Make sure you have Regular expression selected (the shortcut is Alt-Cmd-R)
  4. Type :(\w*) => in Find what:
  5. Type $1: in Replace with:
  6. Click Replace All or press Ctrl-Alt-Enter

Done.