class BoardGameGrid::Direction
Direction
¶ ↑
The Direction
that something is moving on a 2d plane
Attributes
x[R]
@return [Fixnum] the x magnitude.
y[R]
@return [Fixnum] the y magnitude.
Public Class Methods
new(dx, dy)
click to toggle source
New objects can be instantiated with
@param [Fixnum] dx
the dx magnitude.
@param [Fixnum] dy
the dy magnitude.
Example:¶ ↑
# Instantiates a new Direction BoardGameGrid::Direction.new(1, 1)
# File lib/board_game_grid/direction.rb, line 19 def initialize(dx, dy) x = dx == 0 ? dx : dx/dx.abs y = dy == 0 ? dy : dy/dy.abs @x, @y = x, y end
Public Instance Methods
==(other)
click to toggle source
Check if directions are equal by seeing if their magnitudes are equal.
@param [Direction] other
the other direction to compare to.
@return [Boolean]
# File lib/board_game_grid/direction.rb, line 38 def ==(other) self.x == other.x && self.y == other.y end