Sha256: 0b48b58352b6e0ba8ca4ba11d6daa3f7f7d105dd0223ef7212568b5fbd338110

Contents?: true

Size: 614 Bytes

Versions: 4

Compression:

Stored size: 614 Bytes

Contents

# frozen_string_literal: true

# Point value object

module Robot
  class Point
    attr_reader :x, :y

    def initialize(x:, y:)
      @x = x
      @y = y
    end

    def north
      Point.new(x: x, y: y + 1)
    end

    def south
      Point.new(x: x, y: y - 1)
    end

    def east
      Point.new(x: x + 1, y: y)
    end

    def west
      Point.new(x: x - 1, y: y)
    end

    def ==(other)
      x == other.x && y == other.y
    end

    def >(other)
      x > other.x || y > other.y
    end

    def <(other)
      x < other.x || y < other.y
    end

    def to_s
      "#{x}, #{y}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
robot_rea-0.1.9 lib/robot/point.rb
robot_rea-0.1.8 lib/robot/point.rb
robot_rea-0.1.7 lib/robot/point.rb
robot_rea-0.1.6 lib/robot/point.rb