Is Hash Rocket deprecated?

半腔热情 提交于 2019-11-26 15:07:43

The author of that blog post is being overly dramatic and foolish, the => is still quite necessary. In particular:

  1. You must use the rocket for symbols that require quoting: :'where.is' => x is valid but 'where.is': x is not. Ruby 2.2 has fixed this problem so you can say 'where.is': x in Ruby 2.2+.
  2. You must use the rocket for symbols that are not valid labels: :$set => x is valid but $set: x is not. In Ruby 2.2+ you can get around this problem with quotes: '$set': x will do The Right Thing.
  3. You must use the rocket if you use keys in your Hashes that aren't symbols: 's' => x is valid but 's': x is something completely different.

You can kludge around the above in the obvious manner of course:

h = { }
h[:'where.is'] = 'pancakes house?'
# etc.

but that's just ugly and unnecessary.

The rocket isn't going anywhere without crippling Ruby's Hashes.

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