Class: JustChess::Direction
- Inherits:
-
Object
- Object
- JustChess::Direction
- Defined in:
- lib/just_chess/direction.rb
Overview
Direction
The Direction that something is moving on a 2d plane
Instance Attribute Summary collapse
-
#x ⇒ Fixnum
readonly
The x magnitude.
-
#y ⇒ Fixnum
readonly
The y magnitude.
Instance Method Summary collapse
-
#initialize(dx, dy) ⇒ Direction
constructor
New objects can be instantiated with.
Constructor Details
#initialize(dx, dy) ⇒ Direction
22 23 24 25 26 27 |
# File 'lib/just_chess/direction.rb', line 22 def initialize(dx, dy) x = dx == 0 ? dx : dx/dx.abs y = dy == 0 ? dy : dy/dy.abs @x, @y = x, y end |
Instance Attribute Details
#x ⇒ Fixnum (readonly)
Returns the x magnitude.
30 31 32 |
# File 'lib/just_chess/direction.rb', line 30 def x @x end |
#y ⇒ Fixnum (readonly)
Returns the y magnitude.
33 34 35 |
# File 'lib/just_chess/direction.rb', line 33 def y @y end |