From ae2db50873a760162053ed43a01c8d84872bd7c8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 20 May 2007 23:19:10 +0000 Subject: Document Object#blank?. Closes #6491. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6793 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/core_ext/blank.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/blank.rb') diff --git a/activesupport/lib/active_support/core_ext/blank.rb b/activesupport/lib/active_support/core_ext/blank.rb index 80feaf5cc6..d2a940f5b9 100644 --- a/activesupport/lib/active_support/core_ext/blank.rb +++ b/activesupport/lib/active_support/core_ext/blank.rb @@ -1,6 +1,12 @@ -class Object - # "", " ", nil, [], and {} are blank - def blank? #:nodoc: +class Object + # An object is blank if it's nil, empty, or a whitespace string. + # For example, "", " ", nil, [], and {} are blank. + # + # This simplifies + # if !address.nil? && !address.empty? + # to + # if !address.blank? + def blank? if respond_to?(:empty?) && respond_to?(:strip) empty? or strip.empty? elsif respond_to?(:empty?) @@ -47,4 +53,4 @@ class Numeric #:nodoc: def blank? false end -end \ No newline at end of file +end -- cgit v1.2.3