Module: ActiveSupport::Tryable
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#try(method_name = nil, *args, &b) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/active_support/core_ext/object/try.rb', line 7 def try(method_name = nil, *args, &b) if method_name.nil? && block_given? if b.arity == 0 instance_eval(&b) else yield self end elsif respond_to?(method_name) public_send(method_name, *args, &b) end end |
#try!(method_name = nil, *args, &b) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/active_support/core_ext/object/try.rb', line 20 def try!(method_name = nil, *args, &b) if method_name.nil? && block_given? if b.arity == 0 instance_eval(&b) else yield self end else public_send(method_name, *args, &b) end end |