Handy textmate snippet to convert hash syntax

by tokumine

This is one of those things that I’ve known existed for years, but I’ve always avoided because of a previous irrational fear of regexes.

Sometimes you may want to go from this:

h = {
:a => "b",
:b => "c"
....
}

to

h = {}
h[:a] = "b"
h[:b] = "c"

Textmate regex Find & Replace to the rescue

Screen shot 2010-09-20 at 21.30.06

find

: (.*?)\s=>

replace

 h[:$1] =

Voila. Textmate allows access to the matched items in the regex for substitution in to your replace string.

Advertisements