Why is hash-rocket taught when it's outdated?


#1

I'm just going through the course and in tutorial 12, the course suddenly tells you you've used something deprecated until now. So why teach it at all? Or rather, why teach something and then say "it's wrong!"?


#2

The hash rocket is still used in many situations.


#3

As you can see here, hashrocket is still used in many situations. To quote:

  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 not.

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.

Credits to SO user - mu is too short.


#4

Looks like post 3 beat me to it, but I came here because I just finished the lesson, and I was wondering the same thing. However, it clearly says in the instructions that the hash rocket is still used in many Ruby apps that were designed under an older version of Ruby. Also, as 3 pointed out, there are instances where the rocket is still required in current Ruby apps.