lib/rails_extensions.rb
def nil_safe_compare(a, b)
  if a.nil? && b.nil?
    0
  elsif a.nil?
    -1
  elsif b.nil?
    1
  else
    a <=> b
  end
end
# =============================================================================
# A wrapper for the <=> operator that handles nil arguments correctly,
# ordering them before non-nil objects.
A wrapper for the <=> operator that handles nil arguments correctly,
ordering them before non-nil objects.
A wrapper for the < = > operator that handles nil arguments correctly ordering them before non - nil objects .
def nil_safe_compare(a, b)
  if a.nil? && b.nil?
    0
  elsif a.nil?
    -1
  elsif b.nil?
    1
  else
    a <=> b
  end
end
def nil_safe_compare ( a , b ) if a . nil? && b . nil? 0 elsif a . nil? - 1 elsif b . nil? 1 else a <=> b end end
A wrapper for the <=> operator that handles nil arguments correctly,
ordering them before non-nil objects.
A wrapper for the < = > operator that handles nil arguments correctly ordering them before non - nil objects .
a
b