mirror of
https://github.com/github/rails.git
synced 2026-01-30 08:48:06 -05:00
Document Object#blank?. Closes #6491.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6793 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -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.]
|
||||
|
||||
@@ -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
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user