aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorSebastian Martinez <sebastian@wyeworks.com>2011-04-17 20:22:53 -0300
committerSebastian Martinez <sebastian@wyeworks.com>2011-04-17 20:22:53 -0300
commitbb626e785a9ad32d025e429af24654f2af662d09 (patch)
treeb54128eb0cac74172eb4d53fea3da85f39af7bac /activesupport/lib
parent0675047d79912b11a387941e7968d4a651f0cd48 (diff)
downloadrails-bb626e785a9ad32d025e429af24654f2af662d09.tar.gz
rails-bb626e785a9ad32d025e429af24654f2af662d09.tar.bz2
rails-bb626e785a9ad32d025e429af24654f2af662d09.zip
Docs for NilClass#try
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/object/try.rb14
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