This project is archived and is in readonly mode.
ignore_nil{} as a better alternative to try()
-
Joel Chippindale
Your example could be written as follows with try
@user.try(:address).try(:street)What makes using ignore_nil an improvement?
-
Steven Soroka
I don't think .try().try().try().try() is attractive, and it's definitely not DRY.
Much easier to edit and maintain a block around the code than .try sprinkled throughout method calls in the code.
No reason we couldn't support both, I'd think.
-
Pratik
- State changed from new to wontfix
I don't think you should chain try(). So I'm happy with that looking ugly. Don't think something like ignore_nil belongs in core.
