diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-02-01 18:25:03 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-02-01 18:25:03 +0000 |
commit | 886124e688de7b48f32925eca42e4185e487ec84 (patch) | |
tree | 16eaf9f5afc4a742dae80e395cb628657aec5e4d /activesupport/lib/active_support | |
parent | 3be0ad60e4fcdafd4817508a21340dbf1bda6cb4 (diff) | |
download | rails-886124e688de7b48f32925eca42e4185e487ec84.tar.gz rails-886124e688de7b48f32925eca42e4185e487ec84.tar.bz2 rails-886124e688de7b48f32925eca42e4185e487ec84.zip |
Merge docrails
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/try.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/try.rb b/activesupport/lib/active_support/core_ext/try.rb index 0dccd40c55..54a38c5189 100644 --- a/activesupport/lib/active_support/core_ext/try.rb +++ b/activesupport/lib/active_support/core_ext/try.rb @@ -1,6 +1,9 @@ class Object - # Tries to send the method only if object responds to it. Return +nil+ otherwise. - # It will also forward any arguments and/or block like Object#send does. + # Invokes the method identified by the symbol +method+, passing it any arguments + # and/or the block specified, just like the regular Ruby <tt>Object#send</tt> does. + # + # *Unlike* that method however, a +NoMethodError+ exception will *not* be raised + # and +nil+ will be returned instead, if the receiving object is a +nil+ object or NilClass. # # ==== Examples # @@ -12,11 +15,13 @@ class Object # With try # @person.try(:name) # - # Try also accepts arguments/blocks for the method it is trying + # +try+ also accepts arguments and/or a block, for the method it is trying # Person.try(:find, 1) # @people.try(:collect) {|p| p.name} #-- - # This method def is for rdoc only. The alias_method below overrides it as an optimization. + # This method definition below is for rdoc purposes only. The alias_method call + # below overrides it as an optimization since +try+ behaves like +Object#send+, + # unless called on +NilClass+. def try(method, *args, &block) send(method, *args, &block) end |