nonzero?

num.nonzero? â self or nil
Instance Public methods

Returns self if num is not zero, nil otherwise. This behavior is useful when chaining comparisons:

1
2
3
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   #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.