Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>AFAIK there isn't anything like this in plain Ruby. You can create your own like this:</p> <pre><code>class NilClass def blank? true end end class String def blank? self.strip.empty? end end </code></pre> <p>This will work for <code>nil.blank?</code> and <code>a_string.blank?</code> you can extend this (like rails does) for true/false and general objects:</p> <pre><code>class FalseClass def blank? true end end class TrueClass def blank? false end end class Object def blank? respond_to?(:empty?) ? empty? : !self end end </code></pre> <p>References:</p> <p><a href="https://github.com/rails/rails/blob/2a371368c91789a4d689d6a84eb20b238c37678a/activesupport/lib/active_support/core_ext/object/blank.rb#L57" rel="noreferrer">https://github.com/rails/rails/blob/2a371368c91789a4d689d6a84eb20b238c37678a/activesupport/lib/active_support/core_ext/object/blank.rb#L57</a> <a href="https://github.com/rails/rails/blob/2a371368c91789a4d689d6a84eb20b238c37678a/activesupport/lib/active_support/core_ext/object/blank.rb#L67" rel="noreferrer">https://github.com/rails/rails/blob/2a371368c91789a4d689d6a84eb20b238c37678a/activesupport/lib/active_support/core_ext/object/blank.rb#L67</a> <a href="https://github.com/rails/rails/blob/2a371368c91789a4d689d6a84eb20b238c37678a/activesupport/lib/active_support/core_ext/object/blank.rb#L14" rel="noreferrer">https://github.com/rails/rails/blob/2a371368c91789a4d689d6a84eb20b238c37678a/activesupport/lib/active_support/core_ext/object/blank.rb#L14</a> <a href="https://github.com/rails/rails/blob/2a371368c91789a4d689d6a84eb20b238c37678a/activesupport/lib/active_support/core_ext/object/blank.rb#L47" rel="noreferrer">https://github.com/rails/rails/blob/2a371368c91789a4d689d6a84eb20b238c37678a/activesupport/lib/active_support/core_ext/object/blank.rb#L47</a></p> <p>And here is the <code>String.blank?</code> implementation which should be more efficient than the previous one:</p> <p><a href="https://github.com/rails/rails/blob/2a371368c91789a4d689d6a84eb20b238c37678a/activesupport/lib/active_support/core_ext/object/blank.rb#L101" rel="noreferrer">https://github.com/rails/rails/blob/2a371368c91789a4d689d6a84eb20b238c37678a/activesupport/lib/active_support/core_ext/object/blank.rb#L101</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload