diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-06-12 18:30:56 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-06-12 18:30:56 -0500 |
commit | a3caf28da3a22c1326d3d98dcf71483a8edaa55a (patch) | |
tree | ffdee041bedbc1d57eba9cd3dcd4b0879a305158 | |
parent | ea3a7e1bb1efc8b3ca10c4163bc116f3d5e23af1 (diff) | |
download | rails-a3caf28da3a22c1326d3d98dcf71483a8edaa55a.tar.gz rails-a3caf28da3a22c1326d3d98dcf71483a8edaa55a.tar.bz2 rails-a3caf28da3a22c1326d3d98dcf71483a8edaa55a.zip |
Added Object#present? which is equivalent to !Object#blank? [DHH]
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/blank.rb | 5 | ||||
-rw-r--r-- | activesupport/test/core_ext/blank_test.rb | 5 |
3 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index b72f638d82..d0f13afdaa 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *Edge* +* Added Object#present? which is equivalent to !Object#blank? [DHH] + * Added Enumberable#several? to encapsulate collection.size > 1 [DHH] * Add more standard Hash methods to ActiveSupport::OrderedHash [Steve Purcell] diff --git a/activesupport/lib/active_support/core_ext/blank.rb b/activesupport/lib/active_support/core_ext/blank.rb index dfe33162e8..4f8dc4e281 100644 --- a/activesupport/lib/active_support/core_ext/blank.rb +++ b/activesupport/lib/active_support/core_ext/blank.rb @@ -12,6 +12,11 @@ class Object def blank? respond_to?(:empty?) ? empty? : !self end + + # An object is present if it's not blank. + def present? + !blank? + end end class NilClass #:nodoc: diff --git a/activesupport/test/core_ext/blank_test.rb b/activesupport/test/core_ext/blank_test.rb index 061d940383..00fea74639 100644 --- a/activesupport/test/core_ext/blank_test.rb +++ b/activesupport/test/core_ext/blank_test.rb @@ -16,4 +16,9 @@ class BlankTest < Test::Unit::TestCase BLANK.each { |v| assert v.blank?, "#{v.inspect} should be blank" } NOT.each { |v| assert !v.blank?, "#{v.inspect} should not be blank" } end + + def test_present + BLANK.each { |v| assert !v.present?, "#{v.inspect} should not be present" } + NOT.each { |v| assert v.present?, "#{v.inspect} should be present" } + end end |