-
Book Overview & Buying
-
Table Of Contents
Polished Ruby Programming - Second Edition
By :
One of the most useful but misunderstood aspects of Ruby is the difference between symbols and strings. One reason for this is there are certain Ruby methods that deal with symbols, but will still accept strings, as well as methods that perform string-like operations on a symbol. Another reason is the popularity of Rails, and its pervasive use of ActiveSupport::HashWithIndifferentAccess, which allows you to use either a string or a symbol for accessing the same data. However, symbols and strings are very different internally, and serve completely different purposes. As Ruby is focused on programmer happiness and productivity, it will often automatically convert a string to a symbol if it needs a symbol, or a symbol to a string if it needs a string.
A string in Ruby is a series of characters or bytes, useful for storing text or binary data. Unless the string is frozen, you can append to it, modify existing characters in it, or replace it with...