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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to