Method: Object#try!
- Defined in:
- lib/wedge/utilis/try.rb
#try!(*a, &b) ⇒ Object
Same as #try, but raises a NoMethodError exception if the receiver is not nil and does not implement the tried method.
"a".try!(:upcase) # => "A"
nil.try!(:upcase) # => nil
123.try!(:upcase) # => NoMethodError: undefined method `upcase' for 123:Fixnum
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/wedge/utilis/try.rb', line 72 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 |