CHAPTER 2

image

Operators

Expressions

Unlike other programming languages, in Ruby there isn’t a distinction between statements and expressions: everything is evaluated as an expression that produces a return value. The simplest expressions are:

  • literals: values such as numbers, strings, arrays, hashes, etc…
  • variable and constant references: A variable (or a constant) is referenced by citing its name. For example:
    x = 1 # assignment expressionx # variable reference expressionMY_CONST # constant reference
  • method invocations: the (return) value of a method invocation is the value of the last evaluated expression in the body of the method.

Operators

Get Ruby Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.