Ruby Idioms
A number of individual Ruby features can be combined in interesting ways, and the meaning of such idiomatic usage is often not immediately obvious to people new to the language. We use these common Ruby idioms in this book:
- Methods such as empty! and empty?
-
Ruby method names can end with an exclamation mark (a bang method) or a question mark (a predicate method). Bang methods normally do something destructive to the receiver. Predicate methods return true or false, depending on some condition.
- a || b
-
The expression a || b evaluates a. If it isn’t false or nil, then evaluation stops, and the expression returns a. Otherwise, the statement returns b. This is a common way of returning a default value if the first value hasn’t been ...
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