0

What's the difference between these two options? They seem to do the same thing.

sawa
  • 165,429
  • 45
  • 277
  • 381
rpamaral
  • 45
  • 1
  • 5

2 Answers2

2

Both are the same the difference is Hash syntax for 1.9+ Ruby versions and 1.8- Ruby versions:

# Ruby 1.8 Syntax
{:this => 'syntax', 'is' => 'fun'}
# Ruby 1.9 syntax
{this: 'syntax', more: 'fun'}

Check this one as well: "What are the benefits of the new hash syntax in Ruby 1.9?"

As written in the referred post: It just looks nicer--it's syntactic sugar; it ends up being the same thing.

Community
  • 1
  • 1
mohamed-ibrahim
  • 10,837
  • 4
  • 39
  • 51
1

There is no difference. The first is the older syntax for defining a key value pair for hashes. The second was introduced with Ruby 1.9 (I think).

If you're using a version of Ruby pre 1.9 you will have to use the first syntax, otherwise you should use the second syntax.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
margo
  • 2,927
  • 1
  • 14
  • 31
  • There is a difference. There are no "older" and "newer" syntaxes, the JavaScript-style syntax only applies to *some* symbols in Hash literals, if your keys are not a limited set of symbols then you need to use the hashrocket. – mu is too short Apr 29 '15 at 19:57