2
# Invokes the method identified by the symbol +method+, passing it any arguments
3
# and/or the block specified, just like the regular Ruby <tt>Object#send</tt> does.
5
# *Unlike* that method however, a +NoMethodError+ exception will *not* be raised
6
# and +nil+ will be returned instead, if the receiving object is a +nil+ object or NilClass.
11
# @person && @person.name
13
# @person ? @person.name : nil
18
# +try+ also accepts arguments and/or a block, for the method it is trying
19
# Person.try(:find, 1)
20
# @people.try(:collect) {|p| p.name}
22
# This method definition below is for rdoc purposes only. The alias_method call
23
# below overrides it as an optimization since +try+ behaves like +Object#send+,
24
# unless called on +NilClass+.
25
def try(method, *args, &block)
26
send(method, *args, &block)
29
alias_method :try, :__send__