0

I see colons used two different ways in Ruby

:controller => 'pages'

and then

action: => 'home'

I found an explanation here: http://goo.gl/ZKxKVK it seems that the position doesn't matter, could someone clarify this?

lasec0203
  • 2,422
  • 1
  • 21
  • 36

2 Answers2

1

action: => 'home' is not valid syntax.

It should be action: 'home' or :action => 'home'.

These are equivalent. They generate:

{:action=>'home'}
B Seven
  • 44,484
  • 66
  • 240
  • 385
1

Mostly it doesn't matter. Since Ruby 1.9 we can use more short form:

h = { a: 1, b: 2}

But there are some situations where you have to use the longest form, e.g.:

h = {1 => 'a', 2 => 'b'}
h = {"One Two" => 1}
Alexander Shlenchack
  • 3,779
  • 6
  • 32
  • 46