diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-20 23:19:10 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-20 23:19:10 +0000 |
commit | ae2db50873a760162053ed43a01c8d84872bd7c8 (patch) | |
tree | 70fd0d48ffe0f118a8caf0ff0dc4dade7b63170d | |
parent | 5b414190d034e18a3080b74a57a13039134f2834 (diff) | |
download | rails-ae2db50873a760162053ed43a01c8d84872bd7c8.tar.gz rails-ae2db50873a760162053ed43a01c8d84872bd7c8.tar.bz2 rails-ae2db50873a760162053ed43a01c8d84872bd7c8.zip |
Document Object#blank?. Closes #6491.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6793 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/blank.rb | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 69c2c0166a..80b4ad9776 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Document Object#blank?. #6491 [Chris Mear] + * Date, Time, and DateTime#to_json. #8399 [wycats] * Simplify API of assert_difference by passing in an expression that is evaluated before and after the passed in block. See documenation for examples of new API. [Marcel Molina Jr.] 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 |