rails Object.blank? and whitespace
The rails documentation describes Object.blank?
as such:
An object is blank if it's false, empty, or a whitespace string. For example, "", " ", nil, [], and {} are blank.
def blank?
respond_to?(:empty?) ? empty? : !self
end
(from: http://api.rubyonrails.org/classes/Object.html#method-i-blank%3F)
What I don't understand is how it's achieving the functionality of treating whitespace strings as blank.
" ".empty?
returns false. Can anyone shed some light on this? Thanks.
It's overridden for Strings:
From activesupport/core_ext/blank.rb
class String #:nodoc:
def blank?
self !~ /S/
end
end
链接地址: http://www.djcxy.com/p/25796.html