diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-02 15:37:58 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-02 15:37:58 +0000 |
commit | ac58ba60f6cfc272992129ce28808e37391b95d7 (patch) | |
tree | ee02642e1366a1ca168fb6de8f42c67c13be865f /activesupport | |
parent | 4f754985d0d39a9e7831e45809b030b2b3c62d09 (diff) | |
download | rails-ac58ba60f6cfc272992129ce28808e37391b95d7.tar.gz rails-ac58ba60f6cfc272992129ce28808e37391b95d7.tar.bz2 rails-ac58ba60f6cfc272992129ce28808e37391b95d7.zip |
Changed 0.blank? to false rather than true since it violates everyone's expectation of blankness. Closes #2518, Closes #2705.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2849 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/blank.rb | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/object_and_class.rb | 10 | ||||
-rw-r--r-- | activesupport/test/core_ext/blank_test.rb | 13 |
4 files changed, 19 insertions, 10 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 523de67741..be4ed83c54 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Changed 0.blank? to false rather than true since it violates everyone's expectation of blankness. #2518, #2705 [rails@jeffcole.net] + * When loading classes using const_missing, raise a NameError if and only if the file we tried to load was not present. [Nicholas Seckar] * Added petabytes and exebytes to numeric extensions #2397 [timct@mac.com] diff --git a/activesupport/lib/active_support/core_ext/blank.rb b/activesupport/lib/active_support/core_ext/blank.rb index 113a8645f9..f4c0b24c25 100644 --- a/activesupport/lib/active_support/core_ext/blank.rb +++ b/activesupport/lib/active_support/core_ext/blank.rb @@ -30,7 +30,3 @@ class String #:nodoc: empty? || strip.empty? end end - -class Numeric #:nodoc: - alias_method :blank?, :zero? -end
\ No newline at end of file diff --git a/activesupport/lib/active_support/core_ext/object_and_class.rb b/activesupport/lib/active_support/core_ext/object_and_class.rb index cff8fca5bb..1e080d35a4 100644 --- a/activesupport/lib/active_support/core_ext/object_and_class.rb +++ b/activesupport/lib/active_support/core_ext/object_and_class.rb @@ -14,19 +14,17 @@ class Object #:nodoc: subclasses end - # "", " ", nil, and 0 are all blank + # "", " ", nil, [], and {} are blank def blank? if respond_to?(:empty?) && respond_to?(:strip) - strip.empty? - elsif respond_to? :empty? + empty? or strip.empty? + elsif respond_to?(:empty?) empty? - elsif respond_to? :zero? - zero? else !self end end - + def suppress(*exception_classes) begin yield rescue Exception => e diff --git a/activesupport/test/core_ext/blank_test.rb b/activesupport/test/core_ext/blank_test.rb new file mode 100644 index 0000000000..2aba73a008 --- /dev/null +++ b/activesupport/test/core_ext/blank_test.rb @@ -0,0 +1,13 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/object_and_class' +require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/blank' + +class BlankTest < Test::Unit::TestCase + BLANK = [nil, false, '', ' ', " \n\t \r ", [], {}] + NOT = [true, 0, 1, 'a', [nil], { nil => 0 }] + + def test_blank + BLANK.each { |v| assert v.blank? } + NOT.each { |v| assert !v.blank? } + end +end |