0

Possible Duplicate:
What's the difference between colon “:” and fat arrow “=>”

I recently came across this line:

<%= link_to "sample app", '#', id: "logo" %>

I know about Hashes and the immutable keys that look like {:id => "logo"} but what is id:? If this is a hash, why does it not follow the normal convention?

Community
  • 1
  • 1
Ayrton Senna
  • 3,735
  • 5
  • 34
  • 52

1 Answers1

5

That's the new syntax introduced with Ruby 1.9. You can write it like that, or you could write it like this also:

{ :id => "logo" }

The JSON style is just supported as a shorter alternative, and for people who like JavaScript.

Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
  • 1
    I always thought it was for people who hate anyone using Ruby 1.8.7. – tadman Oct 01 '12 at 02:46
  • Actually, it is a transitional feature for introducing "proper" keyword arguments in a mostly backwards-compatible fashion in a future version of Ruby. – Jörg W Mittag Oct 01 '12 at 09:28