Sha256: ebf6b5b0ba4ee61a03c0d2d5fb586b9a4ac910eddcb0972e71f287e328221d5b

Contents?: true

Size: 860 Bytes

Versions: 7

Compression:

Stored size: 860 Bytes

Contents

module JustCheckers

  # = Direction
  #
  # The Direction that something is moving on a 2d plane
  class Direction

    # New objects can be instantiated with
    #
    # @param [Fixnum] x
    #   the x magnitude.
    #
    # @param [Fixnum] y
    #   the y magnitude.
    #
    # ==== Example:
    #   # Instantiates a new Direction
    #   JustCheckers::Direction.new({
    #     x: 1,
    #     y: 1
    #   })
    def initialize(x, y)
      @x, @y = x, y
    end

    # @return [Fixnum] the x magnitude.
    attr_reader :x
    
    # @return [Fixnum] the y magnitude.
    attr_reader :y

    # Check if directions are equal by seeing if their magnitudes are equal.
    #
    # @param [Direction] other
    #   the other direction to compare to.
    #
    # @return [Boolean]
    def ==(other)
      self.x == other.x && self.y == other.y
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
just_checkers-0.3.3 lib/just_checkers/direction.rb
just_checkers-0.3.2 lib/just_checkers/direction.rb
just_checkers-0.3.1 lib/just_checkers/direction.rb
just_checkers-0.3.0 lib/just_checkers/direction.rb
just_checkers-0.2.0 lib/just_checkers/direction.rb
just_checkers-0.1.3 lib/just_checkers/direction.rb
just_checkers-0.1.2 lib/just_checkers/direction.rb