Class: Polynomials::Point
- Inherits:
-
Object
- Object
- Polynomials::Point
- Includes:
- Comparable
- Defined in:
- lib/polynomials/point.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#x ⇒ Object
(also: #to_f)
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(x, y) ⇒ Point
constructor
A new instance of Point.
- #to_s ⇒ Object
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
#x ⇒ Object 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 |
#y ⇒ Object
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
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_s ⇒ Object
19 20 21 |
# File 'lib/polynomials/point.rb', line 19 def to_s "(#{self.x.inspect},#{self.y.inspect})" end |