Search code examples
rubysyntaxsemantics

What is the difference between : and "" in Ruby hashes?


I see some people using hash(es) like this:

end_points = { "dev" => "http://example.com"}

and in other places using this:

 end_points = { :dev => "http://example.com"}

What is the difference between these two approaches?


Solution

  • "" declares a String. : declares a Symbol. If you're using a hash, and you don't need to alter the key's value or keep it around for anything, use a symbol.

    Check this out for a more elaborate explanation.