Do. Or Do Not. There Is No Try - Object#try Considered Harmful
Object#try is quite a commonly used method in Rails applications to cover cases where there is a possibility of dealing with a nil value or to provide flexible interface for handling cases where some kind of object doesn’t necessarily implement given method. Thanks to try, we may avoid getting NoMethodError. So it seems like it’s perfect, right? No NoMethodError exception, no problem?
Well, not really. There are some severe problems with using Object#try, and usually, it’s quite easy to implement a solution that would be much better.
Post a comment