Numbers and Expressions in Ruby


When programming, an expression is a combination of data (such as numbers or strings of text), operators
(such as + or -), and variables that, when understood by the computer, result in an answer of some form.

1 + 2
"a" + "b" + "c"
100 - 5 * (2 - 1)
x + y


Variables are placeholders or references to objects, including numbers, text, or any types of objects you’ve chosen to create.

x = 10
puts x

Here you assign the numeric value of 10 to a variable called x. Be aware that you always need to initialize
variables (that is, assign a value to them) before using them, otherwise you will end up with an error.
You can name variables however you like, with only a few limitations. Variable names must be a single
unit (no spaces!); must start with either a letter or an underscore; must contain only letters, numbers, or
underscores; and are case sensitive. Table 3-1 demonstrates variable names that are valid and invalid.