Appendix 2I Can’t Look It Up!

Ruby has a lot of notation and typography that is called by a name that isn’t necessarily obvious, making it hard to search for the meaning of a particular line of code. Here are a few particularly important symbols:

Symbol

Name

Functionality

||=

Or-equals

Is like other Ruby operate and assign operators. x ||= y is equivalent to x = x || y. Because of Ruby’s short circuit of boolean operators, the expression means that if x is nil, the new value is y, and if x isn’t nil, then x’s value remains the same. Is often used as a shortcut to set a default value.

=~ !~

Match operators

With a string on one side of the operator and a regular expression on the other, =~ returns true if the string matches the regular expression, ...

Get Programming Ruby 3.3 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.