AS guide: documents Object#presence

This commit is contained in:
Xavier Noria
2009-12-30 22:53:44 +01:00
parent 2e59151c5f
commit 7f8d2cdb17

View File

@@ -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: