Class: Polynomials::Point

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/polynomials/point.rb

Direct Known Subclasses

Extremum, InflectionPoint, Root

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Point

Returns a new instance of Point.



15
16
17
# File 'lib/polynomials/point.rb', line 15

def initialize(x,y)
  @x,@y = x,y
end

Instance Attribute Details

#xObject Also known as: to_f

Returns the value of attribute x.



4
5
6
# File 'lib/polynomials/point.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/polynomials/point.rb', line 4

def y
  @y
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/polynomials/point.rb', line 23

def <=>(other)
  if self.x < other.x
    -1
  elsif self.x > other.x
    1
  elsif self.x == other.x && self.y == other.y
    0
  end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/polynomials/point.rb', line 33

def eql?(other)
  self.x == other.x &&
    self.y == other.y &&
    other.class == self.class
end

#to_sObject



19
20
21
# File 'lib/polynomials/point.rb', line 19

def to_s
  "(#{self.x.inspect},#{self.y.inspect})"
end