Chapter 6. Symbols and Ranges
Two fairly Rubyesque objects are symbols and ranges. They are covered together in this chapter not because they are related but because there is not so much to say about them. The Ruby concept of a symbol is sometimes difficult to grasp. If you are familiar with the concept of "atoms" in Lisp, you can think of Ruby symbols as being similar. But rather than give a lengthy and abstruse definition, I will concentrate on what can be done with a symbol and how it can be used. After all, the question "What is a number?" could have a complex answer, but we all understand how to use and manipulate numbers. Ranges are simpler. A range is simply a representation of a group or collection delimited by its endpoints. Similar constructs exist in Pascal, PHP, and even SQL. Let's look at symbols and ranges in greater detail, and see how we can use them in everyday Ruby code. |