Introduction
In this article, we’ve covered everything you need to know about ordering points in ruby.
Ruby is a flexible, open-source programming language with an emphasis on productivity and simplicity. It features a beautiful syntax that is simple to read and write.
A point object, on the other hand, is an object representing a Point in N-dimensional space. It supports all of the familiar Vector methods and adds convenience accessors for those variables you learned in your high school geometry class (x, y, z).

Ordering Points in Ruby
Ordering Points in ruby means to order the points object in ruby in a certain way. Let's say that in order to compare and sort Point objects, we want to create an ordering. There are many methods to arrange points, but we'll decide to arrange them according to how far they are from the origin. The Pythagorean theorem, which takes the square root of the sum of the squares of the X and Y coordinates, is used to calculate this distance (or magnitude).

We simply need to declare the <=> operator and add the Comparable module in order to define this ordering for Point objects. This combines our definition of the general <=> operator with relational operator implementations that are based on our implementation of the general <=> operator. The object provided to the <=> operator should be compared to the self.
It should return -1 if the self is smaller than that object (in this case, nearer to the origin). The function ought to return 0 if the two items are equal. And the procedure should return 1 if the self is greater than the supplied object. If the arguments object and self are of incomparable types, the procedure should return nil. Our implementation of <=> is shown in the code that follows. There are two aspects of it worth mentioning. First, it compares the sum of the squares of the coordinates rather than using the Math.sqrt technique.
Second, it simply transfers control to the <=> operator of the Float class after computing the square sums:
include Comparable
# Establish a point order depending on how far away from the origin of each point is.
# The Comparable module needs this method to function.
def <=>(another)
return nil unless another.instance_of? Point
@x**2 + @y**2 <=> another.x**2 + another.y**2
end
Keep in mind that the Comparable module contains a == function that makes use of our <=> declaration. The == method, which is the outcome of our distance-based comparison operator, regards the points (1,0) and (0,1) as being equal. However, since our Point class clearly defines its own == method, Comparable's == function is never used. The definitions of equality for the == and <=> operators should, ideally, be consistent. Since our Point class did not allow for this, we are left with operators that permit the following:
x,y = Point.new(1,0), Point.new(0,1)
x == y # => false: x is not equal to y
x < y # => false: x is not less than y
x > y # => false: x is not greater than y
The Enumerable module defines a number of methods, including sort, min, and max, although it should be noted that these methods only function if the objects being enumerated support the <=> operator.