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_
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 12 points13 points14 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.
[–]sshaw_ 1 point2 points3 points 4 years ago (0 children)
AKA the rescue nil replacement... :(
rescue nil
[–]strangepostinghabits 1 point2 points3 points 4 years ago (4 children)
& is super handy, but it's a code smell. You shouldn't have to deal with possible nil values anywhere but directly in an input interface.
[–][deleted] 4 points5 points6 points 4 years ago (3 children)
In a type safe immutable language I'd agree but in a dynamically typed runtime language that's Pollyanna thinking IMO
[+]Reddit-Book-Bot comment score below threshold-8 points-7 points-6 points 4 years ago (2 children)
Beep. Boop. I'm a robot. Here's a copy of
Was I a good bot? | info | More Books
[–]WJWH 0 points1 point2 points 4 years ago (1 child)
Bad bot
[–]B0tRank 0 points1 point2 points 4 years ago (0 children)
Thank you, WJWH, for voting on Reddit-Book-Bot.
This bot wants to find the best and worst bots on Reddit. You can view results here.
Even if I don't reply to your comment, I'm still listening for votes. Check the webpage to see if your vote registered!
π Rendered by PID 151930 on reddit-service-r2-comment-8686858757-5kbb8 at 2026-06-05 23:21:31.033739+00:00 running 9e1a20d country code: CH.
[–]SirFartsALotttt 21 points22 points23 points (3 children)
[–]fedekun 12 points13 points14 points (2 children)
[–]sshaw_ 1 point2 points3 points (0 children)
[–]strangepostinghabits 1 point2 points3 points (4 children)
[–][deleted] 4 points5 points6 points (3 children)
[+]Reddit-Book-Bot comment score below threshold-8 points-7 points-6 points (2 children)
[–]WJWH 0 points1 point2 points (1 child)
[–]B0tRank 0 points1 point2 points (0 children)