Answer the question
In order to leave comments, you need to log in
What is the difference between a character and a string? Where it is possible, where it is necessary to use symbols instead of lines?
The question arose, what is the difference between a string and a character in Ruby? Of course, I realized that two identical strings are two different objects, that object_id
they will have different, then that two identical characters are two identical objects that have a single one object_id
, and that it is stored in memory once, "without rollback", then that a character is an immutable string, and so on. etc. But are these really all "properties" of a symbol in Ruby?
From the first question, the second follows: where can you use symbols, where can you replace strings with symbols, where do you need to do this, where is it convenient?
Answer the question
In order to leave comments, you need to log in
You understood the differences correctly, symbols are usually used as keys in a hash (eg { key: 'value' } instead of {'key' => 'value' }).
Here is an extended question to both of your questions: stackoverflow.com/questions/16621073/when-to-use-s...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question