3.7. Constants up close

Many classes consist principally of instance methods and/or class methods. But constants are an important and common third ingredient in many classes. You’ve already seen constants used as the names of classes. Constants can also be used to set and preserve important data values in classes.

Later, we’ll look at the scope of constants and techniques for nesting them inside multilevel classes and modules. For now, we’ll focus on the basics of how to use them—and the question of how constant these constants really are.

3.7.1. Basic use of constants

The name of every constant begins with a capital letter. You assign to constants much as you do to variables.

Let’s say we decide to establish a list of predefined venues for the ...

Get The Well-Grounded Rubyist, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.