diff options
author | Sebastian Martinez <sebastian@wyeworks.com> | 2011-04-17 20:22:53 -0300 |
---|---|---|
committer | Sebastian Martinez <sebastian@wyeworks.com> | 2011-04-17 20:22:53 -0300 |
commit | bb626e785a9ad32d025e429af24654f2af662d09 (patch) | |
tree | b54128eb0cac74172eb4d53fea3da85f39af7bac /activesupport/lib/active_support/core_ext | |
parent | 0675047d79912b11a387941e7968d4a651f0cd48 (diff) | |
download | rails-bb626e785a9ad32d025e429af24654f2af662d09.tar.gz rails-bb626e785a9ad32d025e429af24654f2af662d09.tar.bz2 rails-bb626e785a9ad32d025e429af24654f2af662d09.zip |
Docs for NilClass#try
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/try.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb index 04619124a1..341a6237cb 100644 --- a/activesupport/lib/active_support/core_ext/object/try.rb +++ b/activesupport/lib/active_support/core_ext/object/try.rb @@ -34,7 +34,19 @@ class Object end end -class NilClass #:nodoc: +class NilClass + # Instances of NilClass return always +nil+ + # It becomes specially helpful when navigating through associations that may return nil + # + # === Examples + # + # nil.try(:name) => nil + # + # Without try + # @person && @person.children.first && @person.children.first.name + # + # With try + # @person.try(:children).try(:first).try(:name) def try(*args) nil end |