Added Object#present? which is equivalent to !Object#blank? [DHH]
This commit is contained in:
parent
ea3a7e1bb1
commit
a3caf28da3
@ -1,5 +1,7 @@
|
|||||||
*Edge*
|
*Edge*
|
||||||
|
|
||||||
|
* Added Object#present? which is equivalent to !Object#blank? [DHH]
|
||||||
|
|
||||||
* Added Enumberable#several? to encapsulate collection.size > 1 [DHH]
|
* Added Enumberable#several? to encapsulate collection.size > 1 [DHH]
|
||||||
|
|
||||||
* Add more standard Hash methods to ActiveSupport::OrderedHash [Steve Purcell]
|
* Add more standard Hash methods to ActiveSupport::OrderedHash [Steve Purcell]
|
||||||
|
@ -12,6 +12,11 @@ class Object
|
|||||||
def blank?
|
def blank?
|
||||||
respond_to?(:empty?) ? empty? : !self
|
respond_to?(:empty?) ? empty? : !self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# An object is present if it's not blank.
|
||||||
|
def present?
|
||||||
|
!blank?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class NilClass #:nodoc:
|
class NilClass #:nodoc:
|
||||||
|
@ -16,4 +16,9 @@ def test_blank
|
|||||||
BLANK.each { |v| assert v.blank?, "#{v.inspect} should be blank" }
|
BLANK.each { |v| assert v.blank?, "#{v.inspect} should be blank" }
|
||||||
NOT.each { |v| assert !v.blank?, "#{v.inspect} should not be blank" }
|
NOT.each { |v| assert !v.blank?, "#{v.inspect} should not be blank" }
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user