nonzero?()
public
Returns num if num is not zero, nil otherwise.
This behavior is useful when chaining comparisons:
a = %w( z Bb bB bb BB a aA Aa AA A )
b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b }
b
Show source
/*
* call-seq:
* num.nonzero? => num or nil
*
* Returns <i>num</i> if <i>num</i> is not zero, <code>nil</code>
* otherwise. This behavior is useful when chaining comparisons:
*
* a = %w( z Bb bB bb BB a aA Aa AA A )
* b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b }
* b
*/
static VALUE
num_nonzero_p(num)
VALUE num;
{
if (RTEST(rb_funcall(num, rb_intern("zero?"), 0, 0))) {
return Qnil;
}
return num;
}