4 ms·
I'm not sure I agree on the syntax being simpler/more readable... try() seems pretty clear-cut to me.
by Hovertruck 15y ago
I'm not sure I agree on the syntax being simpler/more readable... try() seems pretty clear-cut to me.
- JonnieCache 15y agoI mean that I prefer chaining the methods rather than passing the method name as a symbol to try. You're right, the name 'andand' isnt as clear as 'try,' it comes from its creation as a replacement for the use of the && operator as a guard. If try() returned a proxy object that used method_missing to accept method calls rather than just being passed a symbol, we'd have the best of both worlds. It is unfortunately a fairly wanton case of demeter violation, but rails is pretty much based on wanton demeter violation anyway, or at least it feels like that at times. Generally the times when I'm trying to write integration tests for some overly clever library.
- themgt 15y agoI prefer the implementation of Mongoid's #do_or_do_not, which checks for the method's existence rather than the object's (http://rubydoc.info/github/mongoid/mongoid/master/Mongoid/Extensions/Object/Yoda http://rubydoc.info/github/mongoid/mongoid/master/Mongoid/Ex...)