Hi Jeff, The best way to argue for an addition like this is to show some before/after code. Preferably a few examples. Then that'll illustrate how/when this is needed and people can chime in on alternative ways to accomplish the same. Off the top of my head, I can't remember a single time I've wanted something like this in the past 15 years. But a representative example could perhaps jog the memory.
If the before/after cases are compelling, we could then talk about naming etc. Not a big fan of using a synonym in this way to do something so similar and yet subtlety different. But that's getting ahead of ourselves. First a general need should be clarified. On Wednesday, March 8, 2017 at 11:29:55 PM UTC+1, Jeff Davenport wrote: > > I find myself needing to run a method and if the method does not exist, > have it return itself, instead of nil quite often, I think this change > could be used fairly widely. > > module ActiveSupport > module Tryable #:nodoc: > def try(*a, &b) > try!(*a, &b) if a.empty? || respond_to?(a.first) > end > > # NEW METHOD > def attempt(*a, &b) > try(*a, &b) || self > end > end > end > > > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.