January 2024
Intermediate to advanced
718 pages
20h 15m
English
So far, we’ve been fairly cavalier in our use of expressions in Ruby. After all, a = b + c is pretty standard stuff. That said, Ruby expressions are different than what you might see in JavaScript, Python, or Java, and there’s a lot of power and flexibility there. You could write a whole lot of Ruby code without reading any of this chapter, but it wouldn’t be as much fun.
One of the first differences in Ruby is that anything that can reasonably return a value does: just about everything is an expression. What does this mean in practice?
Well, for one thing, we have the ability to chain statements together:
| | a = b = c = 0 |
| | [3, 1, 7, 0].sort.reverse # => [7, 3, 1, 0] |
Code structures that are statements in languages ...
Read now
Unlock full access