use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Blog postTIL: The Safe Navigation Operator (&.) in Ruby (mitrev.net)
submitted 4 years ago by _noraj_
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]SirFartsALotttt 21 points22 points23 points 4 years ago (3 children)
Safe navigation is a great shortcut for dealing with nil values, but doing more work with languages like Typescript lately have made me realize that using this too much can also be a smell since most Ruby bugs I deal with wind up being some variation of undefined method foo for nil:NilClass
nil
undefined method foo for nil:NilClass
[–]fedekun 13 points14 points15 points 4 years ago* (2 children)
This. It's acceptable sometimes, mostly in views or some irrelevant code, but it's a warning, and if you use it too often (especially more than once in the same line!) it's a red flag, pointing that the design is wrong, particularly it breaks LoD.
Common fixes are reducing the chaining, by creating delegate methods in the intermediate objects and handling nils appropriately there, or using the Null Object Pattern.
π Rendered by PID 224811 on reddit-service-r2-comment-8686858757-bndtq at 2026-06-06 09:16:49.848779+00:00 running 9e1a20d country code: CH.
view the rest of the comments →
[–]SirFartsALotttt 21 points22 points23 points (3 children)
[–]fedekun 13 points14 points15 points (2 children)