Permalink
Browse files

Fixed failing test for Object#blank?

false.should be_blank  # => false

When adding a core extension for Object#blank?,
it should match the de-facto standard implementation
by ActiveSupport (and others).
  • Loading branch information...
1 parent bc3b4eb commit 8465e82960ec9ce9f4b2dbada982948614cd219d @rubiii rubiii committed Sep 17, 2011
Showing with 3 additions and 48 deletions.
  1. +3 −48 lib/crack/core_extensions.rb
@@ -6,59 +6,14 @@ class Object #:nodoc:
# @example [].blank? #=> true
# @example [1].blank? #=> false
# @example [nil].blank? #=> false
- #
+ #
# Returns true if the object is nil or empty (if applicable)
def blank?
- nil? || (respond_to?(:empty?) && empty?)
+ respond_to?(:empty?) ? empty? : !self
end unless method_defined?(:blank?)
end # class Object
-class Numeric #:nodoc:
- # @return <TrueClass, FalseClass>
- #
- # Numerics can't be blank
- def blank?
- false
- end unless method_defined?(:blank?)
-end # class Numeric
-
-class NilClass #:nodoc:
- # @return <TrueClass, FalseClass>
- #
- # Nils are always blank
- def blank?
- true
- end unless method_defined?(:blank?)
-end # class NilClass
-
-class TrueClass #:nodoc:
- # @return <TrueClass, FalseClass>
- #
- # True is not blank.
- def blank?
- false
- end unless method_defined?(:blank?)
-end # class TrueClass
-
-class FalseClass #:nodoc:
- # False is always blank.
- def blank?
- true
- end unless method_defined?(:blank?)
-end # class FalseClass
-
class String #:nodoc:
- # @example "".blank? #=> true
- # @example " ".blank? #=> true
- # @example " hey ho ".blank? #=> false
- #
- # @return <TrueClass, FalseClass>
- #
- # Strips out whitespace then tests if the string is empty.
- def blank?
- strip.empty?
- end unless method_defined?(:blank?)
-
def snake_case
return self.downcase if self =~ /^[A-Z]+$/
self.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
@@ -114,7 +69,7 @@ def normalize_param(key, value)
param
end
-
+
# @return <String> The hash as attributes for an XML tag.
#
# @example

0 comments on commit 8465e82

Please sign in to comment.