Module: ActiveSupport::Tryable

Included in:
Delegator, Object
Defined in:
lib/active_support/core_ext/object/try.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#try(*a, &b) ⇒ Object



5
6
7
# File 'lib/active_support/core_ext/object/try.rb', line 5

def try(*a, &b)
  try!(*a, &b) if a.empty? || respond_to?(a.first)
end

#try!(*a, &b) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/active_support/core_ext/object/try.rb', line 9

def try!(*a, &b)
  if a.empty? && block_given?
    if b.arity == 0
      instance_eval(&b)
    else
      yield self
    end
  else
    public_send(*a, &b)
  end
end