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