From bb626e785a9ad32d025e429af24654f2af662d09 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Sun, 17 Apr 2011 20:22:53 -0300 Subject: Docs for NilClass#try --- activesupport/lib/active_support/core_ext/object/try.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/object/try.rb') 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 -- cgit v1.2.3