Confused with Ruby's <=> operator

arscariosus picture arscariosus · Jan 20, 2011 · Viewed 7.3k times · Source

I am confused with Ruby's <=> operator. How does it differ from == or ===? Any comprehensive examples/use case? Thanks.

Answer

ghostdog74 picture ghostdog74 · Jan 20, 2011

<=> is the combined comparison operator. it returns 0 if LHS equals RHS, 1 if LHS is greater than the RHS and -1 if LHS is less than RHs