Why does Ruby expose symbols for explicit use? Isn’t that the sort of optimisation that’s usually handled by the interpreter/compiler?
Why does Ruby expose symbols for explicit use? Isn’t that the sort of optimisation
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Part of the issue is that Ruby strings are mutable. Since every string Ruby allocates must be independent (it can’t cache short/common ones), it’s convenient to have a
Symboltype to let the programmer have what are essentially immutable, memory-efficient strings.Also, they share many characteristics with
enum‘s, but with less pain for the programmer.