+ 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.
4 odpowiedzi
+ 2
Reading this article was useful to me:http://rubylearning.com/blog/2007/11/26/akitaonrails-on-ruby-symbols/
+ 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.
+ 1
Using symbols :id saves memory, because they are only stored once.
+ 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?