bbatsov/ruby-style-guide — pull request #355 by kellyfelkins (2014-08-31 16:28:43+00:00)
Title: Use rocket syntax rather than javascript inspired colon syntax

The new javascript inspired colon separator syntax for Ruby hashes is nice in some situations, but is often confusing. In javascript it is simply a separator. In ruby it is both a separator and an indicator of type.

Here's the good case:

hash = { foo: bar }

A hash with keys that are symbols referencing variables b and d.

But to reference a value in that hash we must revert to the standard type indicator for symbol:

hash[ :foo ]

If the hash key is not a symbol then you must use the traditional rocket separator:

hash = { 'foo' => bar }

Sometimes you would by happy to use a symbol, but your identifier is not easily converted to a symbol:

hash = { foo-ish: bar } # error

event though you could make a valid symbol if you used the traditional syntax:

hash = { :'foo-ish' => bar }
hash = { 'foo-ish': bar } # error

This proposed update to the ruby style guide is recommending we stay with the traditional rocket separator.

Here are some inelegant examples from real code:

# do symbols have the colon at the beginning or the end?
render :new, layout: 'mobile'

# some types lead to mixing of separators
render json: { "success" => "true" }

# some strings are difficult to coerce into symbols
... href: "#", "data-fof-id" => target.id
... relation.where(inviter_id: inviter_id).joins(:invitee).where("users.member" => true).count(:invitee_id)
"X-SMTPAPI" => {category: "activity-digest"}.to_json
html: {"data-modify-action" => :update, style: "display: none"}

# inconsistent for no good reason
gon.rabl :template => 'app/views/command_center/project.rabl', as: :project