Reputation: 11
I am quite new in ruby and rails and get confused in this stuff what is :something and what is something:
please help me out :<
Upvotes: 0
Views: 55
Reputation: 107107
:some_text
is a Symbol
. Whereas some_text:
only makes sense in the context of a hash.
These both hashes are equal:
{ :foo => 'bar' } # "old" hash syntax
{ foo: 'bar' } # simplified newer hash systax, generates a `:foo` hash keys too
The newer syntax has the advantage that it is a bit shorter, but it only works when that hash keys should be symbols. When you need other hash keys, for example integers, then you have to use the "older" syntax like this: { 1 => 'bar' }
Upvotes: 2