Module: AppInfo::Tryable
- Included in:
- Object
- Defined in:
- lib/app_info/core_ext/object/try.rb
Overview
Monkey Patch for Object
Instance Method Summary collapse
Instance Method Details
#try(*a, &b) ⇒ Object
4 5 6 |
# File 'lib/app_info/core_ext/object/try.rb', line 4 def try(*a, &b) try!(*a, &b) if a.empty? || respond_to?(a.first) end |
#try!(*a, &b) ⇒ 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!(*a, &b) if a.empty? && block_given? if b.arity.zero? instance_eval(&b) else yield self end else public_send(*a, &b) end end |