aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_support_core_extensions.textile
diff options
context:
space:
mode:
Diffstat (limited to 'railties/guides/source/active_support_core_extensions.textile')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile8
1 files changed, 8 insertions, 0 deletions
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?
</ruby>
+h4. +presence+
+
+The +presence+ method returns its receiver if +present?+, and +nil+ otherwise. It is useful for idioms like this:
+
+<ruby>
+host = config[:host].presence || 'localhost'
+</ruby>
+
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: