Class: Ein::Position
- Inherits:
-
Object
- Object
- Ein::Position
- Defined in:
- lib/ein/position.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
- #distance_to(position) ⇒ Object
-
#initialize(x, y) ⇒ Position
constructor
A new instance of Position.
- #round ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Position
Returns a new instance of Position.
10 11 12 |
# File 'lib/ein/position.rb', line 10 def initialize(x,y) @x, @y = x,y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
8 9 10 |
# File 'lib/ein/position.rb', line 8 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
8 9 10 |
# File 'lib/ein/position.rb', line 8 def y @y end |
Instance Method Details
#distance_to(position) ⇒ Object
14 15 16 |
# File 'lib/ein/position.rb', line 14 def distance_to(position) Math.sqrt((@x - position.x)**2 + (@y - position.y)**2) # Pythagoras, miss you buddy. RIP end |
#round ⇒ Object
18 19 20 |
# File 'lib/ein/position.rb', line 18 def round Position.new(@x.round, @y.round) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/ein/position.rb', line 22 def to_s "x: #@x, y: #@y" end |