Wednesday, September 24, 2014
Symbols and strings
There is a lot of discussion around symbols and strings in Ruby. I put together a little flashcard explaining the difference. So: a symbol sort of looks like a string, except it is not. A symbol is immutable and reusable; unlike strings, it references one object in memory. For this reason, it makes the lookup of symbols faster. However, symbols cannot be manipulated like strings (hence immutability), which makes them less useful in certain situations. Another problem is that symbols cause memory leaks, since they are not released from the memory. However, the good news is since Ruby 2.2 symbols will be garbage collectible. See this article here.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment