Class: Rubygoal::Coordinate
- Inherits:
-
Struct
- Object
- Struct
- Rubygoal::Coordinate
- Defined in:
- lib/rubygoal/coordinate.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #add(coordinate) ⇒ Object
- #distance(coordinate) ⇒ Object
- #mult(coeficient) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x
4 5 6 |
# File 'lib/rubygoal/coordinate.rb', line 4 def x @x end |
#y ⇒ Object
Returns the value of attribute y
4 5 6 |
# File 'lib/rubygoal/coordinate.rb', line 4 def y @y end |
Instance Method Details
#add(coordinate) ⇒ Object
9 10 11 |
# File 'lib/rubygoal/coordinate.rb', line 9 def add(coordinate) self.class.new(x + coordinate.x, y + coordinate.y) end |
#distance(coordinate) ⇒ Object
5 6 7 |
# File 'lib/rubygoal/coordinate.rb', line 5 def distance(coordinate) Util.distance(x, y, coordinate.x, coordinate.y) end |
#mult(coeficient) ⇒ Object
13 14 15 |
# File 'lib/rubygoal/coordinate.rb', line 13 def mult(coeficient) self.class.new(x * coeficient, y * coeficient) end |
#to_hash ⇒ Object
21 22 23 |
# File 'lib/rubygoal/coordinate.rb', line 21 def to_hash { x: x, y: y } end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/rubygoal/coordinate.rb', line 17 def to_s "(#{x}, #{y})" end |