Appendix A. Ruby Quick Reference
Basic Ruby Syntax
The Ruby language is made up of expressions. Each expression returns a value. Even elements that are just statements in other languages, such as if and for, are expressions in Ruby that return values.
Ruby is a pure object-oriented language. Every variable or constant in Ruby is an object, and there are no basic non-object types. Every variable or literal responds to the basic method call syntax.
A simple Ruby expression is one of the following:
A literal. Ruby has literal syntax for arrays, hashes, numbers, ranges, regular expressions, strings, and symbols.
The name of an existing variable or constant.
A method call, which combines the name of an existing variable or constant with a method name. The basic form of a method call is
<receiver>.<method>(<arguments>). Variants on this form will be discussed later.One of several special expressions invoked by the use of a keyword such as
if, case, orwhile.
Complex expressions can be built using Ruby operators. Variable assignment using = is considered to be a type of operator. Most expressions can also have arbitrarily complex expressions within them — for example, the arguments of a method call are all themselves expressions.
A Ruby expression ends with a line break unless the Ruby interpreter has a reason to believe the expression is intended to continue. The expression continues if there is an open delimiter such as a quotation mark, parenthesis, bracket, or brace. The expression also continues ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access