diff options
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/try.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb index c874691629..bd841771ce 100644 --- a/activesupport/lib/active_support/core_ext/object/try.rb +++ b/activesupport/lib/active_support/core_ext/object/try.rb @@ -5,7 +5,16 @@ require "delegate" module ActiveSupport module Tryable #:nodoc: def try(*a, &b) - try!(*a, &b) if a.empty? || respond_to?(a.first) + return unless a.empty? || respond_to?(a.first) + if a.empty? && block_given? + if b.arity == 0 + instance_eval(&b) + else + yield self + end + else + public_send(*a, &b) + end end def try!(*a, &b) |