+ 1

can't understand symbols !! could anyone explain please ?

Symbols In the previous example we used strings as keys for the hash, but Ruby has a more elegant and faster way for creating and accessing hash indexes than using strings. Symbols are similar to strings, but they are immutable, meaning that they cannot be changed. A symbol is created using a colon and a name, for example: a = :id In the code above :id is a symbol. You can also think of :id as meaning the name of the variable id, and plain id as meaning the value of the variable.

23rd Mar 2017, 11:38 PM
Marwane Chahoud
4 Answers
23rd Apr 2017, 1:59 PM
Elias Zica
Elias Zica - avatar
+ 1
you can use symbols instead of strings if you want to make you code run faster. They are simliar to strings, but they just can't be changed.
24th Mar 2017, 11:55 PM
Steven Wang
Steven Wang - avatar
+ 1
Using symbols :id saves memory, because they are only stored once.
5th May 2017, 7:29 PM
Vira Yanchuk
Vira Yanchuk - avatar
+ 1
Look at the code: arr = { "name" => "John" } arr = { :name => "John" } arr = { name: "John" } All of them doing same task. Which do you think is short?
8th Nov 2017, 12:55 PM
Murat Azizov
Murat Azizov - avatar