diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 69c2c0166a4bf06a6191e9fc3194f00ef78fdb7a..80b4ad9776ae48eb67cc7fcb16874028bce2a63f 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 80feaf5cc6c92c577402682cb44db0ba56052c9f..d2a940f5b98926703aef5cafda6fada5e308f659 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