Module: Fusu::Try
- Included in:
- Fusu
- Defined in:
- lib/fusu/try.rb
Instance Method Summary collapse
Instance Method Details
#try(object, *a, &b) ⇒ Object
3 4 5 6 |
# File 'lib/fusu/try.rb', line 3 def try(object, *a, &b) return nil if object === nil try!(object, *a, &b) if a.empty? || object.respond_to?(a.first) end |
#try!(object, *a, &b) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fusu/try.rb', line 8 def try!(object, *a, &b) if a.empty? && block_given? if b.arity == 0 object.instance_eval(&b) else yield object end else object.public_send(*a, &b) end end |