Empty string: Difference between revisions
Content added Content deleted
(add Ruby) |
|||
Line 336: | Line 336: | ||
s.each_char.to_a.empty?</lang> |
s.each_char.to_a.empty?</lang> |
||
Non-empty expressions: |
Non-empty expressions, in addition to simply negating the above expressions: |
||
<lang ruby>s != "" |
<lang ruby>s != "" |
||
s.length > 0 |
s.length > 0 |
||
s[/./]</lang> |
s[/./]</lang> |
||
Note that we |
Note that we can '''not''' do the following, because the empty string is equivalent to true in Ruby ([[Boolean values#Ruby]]): |
||
<lang ruby>if s then puts "not empty" end</lang> |
<lang ruby>if s then puts "not empty" end</lang> |
||