Skip to content
Browse files

Added native, faster implementations of .blank? for the core types #2286

 [skae]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2319 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 1f4dc25 commit df95567598677a9c109146df8531674e70c2eb80 @dhh dhh committed
Showing with 38 additions and 0 deletions.
  1. +2 −0 activesupport/CHANGELOG
  2. +36 −0 activesupport/lib/active_support/core_ext/blank.rb
View
2 activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added native, faster implementations of .blank? for the core types #2286 [skae]
+
* Fixed clean logger to work with Ruby 1.8.3 Logger class #2245
* Fixed memory leak with Active Record classes when Dependencies.mechanism = :load #1704 [c.r.mcgrath@gmail.com]
View
36 activesupport/lib/active_support/core_ext/blank.rb
@@ -0,0 +1,36 @@
+# The methods here are provided to speed up function blank? in class Object
+class NilClass
+ def blank?
+ true
+ end
+end
+
+class FalseClass
+ def blank?
+ true
+ end
+end
+
+class TrueClass
+ def blank?
+ false
+ end
+end
+
+class Array
+ alias_method :blank?, :empty?
+end
+
+class Hash
+ alias_method :blank?, :empty?
+end
+
+class String
+ def blank?
+ empty? || strip.empty?
+ end
+end
+
+class Numeric
+ alias_method :blank?, :zero?
+end

0 comments on commit df95567

Please sign in to comment.
Something went wrong with that request. Please try again.