From 7f8d2cdb1715ddfaa27eed892df7ca9884e5315a Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 30 Dec 2009 22:53:44 +0100 Subject: [PATCH] AS guide: documents Object#presence --- .../guides/source/active_support_core_extensions.textile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 8ba283122d..0e4f1da7b2 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -48,6 +48,14 @@ The method +present?+ is equivalent to +!blank?+: assert @response.body.present? # same as !@response.body.blank? +h4. +presence+ + +The +presence+ method returns its receiver if +present?+, and +nil+ otherwise. It is useful for idioms like this: + + +host = config[:host].presence || 'localhost' + + h4. +duplicable?+ A few fundamental objects in Ruby are singletons. For example, in the whole live of a program the integer 1 refers always to the same instance: -- GitLab