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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Point

Returns a new instance of Point.



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

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

Class Method Details

.inherited(subclass) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/polynomials/point.rb', line 7

def self.inherited(subclass)
  self.class_eval do 
    define_method :"#{subclass.name.demodulize.underscore}?" do
      self.is_a? subclass
    end
  end
end

Instance Method Details

#<=>(other) ⇒ Object



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

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:



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

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

#to_sObject



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

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