does someone knows if there is method which checks both? if not then
i’ll write my own … but i am curious if there is one for
return x.nil? or blank?
does someone knows if there is method which checks both? if not then
i’ll write my own … but i am curious if there is one for
return x.nil? or blank?
On Dec 6, 2007, at 1:03 PM, Michal G. wrote:
does someone knows if there is method which checks both? if not then
i’ll write my own … but i am curious if there is one forreturn x.nil? or blank?
(x.nil? or x.blank?) is logically equivalent to x.blank? because nil
is blank:
nil.blank? # -> true
So the answer is yes, you are looking for blank? indeed :-).
– fxn
oh thanks … thats good to know
great!
After a quick test it appears that Rails must add the blank? method to
nil. Ruby “out-of-the-box” reports that nil has no blank? method. Just
FYI.
On Dec 6, 7:13 am, Michal G. <rails-mailing-l…@andreas-
I want one that checks for empty + empty array…
According to:
http://noobkit.com/show/ruby/rails/rails-stable/activesupport/object/blank-3f.html
ActiveSupport is what includes the method.
All the code it uses is pretty simple:
def blank?
if respond_to?(:empty?) && respond_to?(:strip)
empty? or strip.empty?
elsif respond_to?(:empty?)
empty?
else
!self
end
end
On Dec 7, 2007 4:58 PM, Robert W. [email protected] wrote:
Posted viahttp://www.ruby-forum.com/.
–
Ryan B.
http://www.frozenplague.net
On Dec 7, 2007, at 8:20 AM, eggie5 wrote:
I want one that checks for empty + empty array…
That’s blank? again.
In Rails blank? has an implementation in Object and a few special
cases. For example in Array
class Array #:nodoc:
alias_method :blank?, :empty?
end
In NilClass it returns true directly:
class NilClass #:nodoc:
def blank?
true
end
end
And there are a few more. See activesupport/lib/active_support/
core_ext/blank.rb.
– fxn
Michal G. wrote:
does someone knows if there is method which checks both? if not then
i’ll write my own … but i am curious if there is one forreturn x.nil? or blank?
x.blank? is equivalent to x.nil? or x.empty?
oh duh…
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs