in Hacking

Ruby compare sort en nonzero?

Just reminder for myself...
The method Numeric#nonzero?
returns self if the number is != 0 else it returns nil

Makes this code possible:

  objects.sort do |a, b|
    (a.lastname <=> b.lastname).nonzero? || (a.firstname <=> b.firstname)
  end
  • Related Content by Tag