Is there any difference between the `:key => “value”` and `key: “value”` hash notations?

后端 未结 5 2011
有刺的猬
有刺的猬 2020-11-22 02:24

Is there any difference between :key => \"value\" (hashrocket) and key: \"value\" (Ruby 1.9) notations?

If not, then I would like to use

5条回答
  •  旧巷少年郎
    2020-11-22 02:51

    key: "value" is a convenience feature of Ruby 1.9; so long as you know your environment will support it, I see no reason not to use it. It's just much easier to type a colon than a rocket, and I think it looks much cleaner. As for there being a gem to do the conversion, probably not, but it seems like an ideal learning experience for you, if you don't already know file manipulation and regular expressions.

提交回复
热议问题