What are the benefits of the new hash syntax in Ruby 1.9?

北城余情 提交于 2019-11-27 16:01:21

It just looks nicer--it's syntactic sugar; it ends up being the same thing.

When mixing keys (ew, why would you do that?) I use the old hash-rocket syntax for the entire hash.

With symbol values I also use the old hash-rocket syntax for the entire hash–this looks icky:

{ ohai: :kthxbye }

I don't like mixing the two styles in the same hash–I think it's confusing.

This is all based on personal preference, though.

It's shorter, and similar to JavaScript notation. Not worth to migrate old notation to the new for any reason, but otherwise choose which you like.

Always keep the code consistent, don't mix notations. It's more readable that way.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!