Don't like 1.9's Symbol-in-Hash syntax? Use hash_syntax

Posted by -

After seeing this post pooh-poohing the new syntax for Symbols as Hash literal keys, I searched around to see if there were any automatic converters for this change. I was surprised to find there are not!

This is the sort of change Laser will be able to do in its sleep, and I've got a local branch presently which performs this conversion. However, Laser currently has a long startup time. Until I switch it to using autoload (which is nontrivial given how Laser bootstraps) I figured I'd whip this one up as a separate gem. Plus, it gave me another chance to use the object_regex gem we developed.

So head on over to hash_syntax and give it a spin. I'll be updating it if this change (the second half of the post) ends up happening, which I personally agree with. In essence, it would generalize the foo: bar syntax to allow quoted symbols, which has come up for me in the past:

  { foo: bar, :"to-19" => baz }

could become

  { foo: bar, "to-19": baz }

if a patch lands.

See the readme for usage, but it's as simple as running this command in a project root:

  hash_syntax --to-18

or

  hash_syntax --to-19

Anyway, check out hash_syntax. Make a fresh commit before you use it just in case!


Enjoy this article? Then feel free to:


Comments