Ruby: colon before vs after

ruby

Solution

You are welcome for both, while creating `Hash` :

{:name => "foo"}
#or
{name: 'foo'} # This is allowed since Ruby 1.9

But basically `:name` is a `Symbol` object in Ruby.

From docs

Hashes allow an alternate syntax form when your keys are always symbols. Instead of

options = { :font_size => 10, :font_family => "Arial" }

You could write it as:

options = { font_size: 10, font_family: "Arial" }

Problem

When using Ruby, I keep getting mixed up with the `:`. Can someone please explain when I'm supposed to use it before the variable name, like `:name`, and when I'm supposed to use it after the variable like `name:`? An example would be sublime.

Original source

Related problems