Sha256: 127c952ae23cb9badaed7d080e0d35d04207cf2f3356deaa4e5f012cdd5b249d
Contents?: true
Size: 1.08 KB
Versions: 10
Compression:
Stored size: 1.08 KB
Contents
module BoardGameGrid # = Point # # A point with an x and y co-ordinates class Point # New objects can be instantiated with # # @param [Fixnum] x # the x co-ordinate. # # @param [Fixnum] y # the y co-ordinate. # # ==== Example: # # Instantiates a new Point # BoardGameGrid::Point.new({ # x: 1, # y: 1 # }) def initialize(x, y) @x, @y = x, y end # @return [Fixnum] the x co-ordinate. attr_reader :x # @return [Fixnum] the y co-ordinate. attr_reader :y # Add a point to another point by adding their co-ordinates and returning a new point. # # @param [Point] other # the other point to add. # # @return [Point] def +(other) self.class.new(self.x + other.x, self.y + other.y) end # Check if popints are equal by seeing if their co-ordinates are equal. # # @param [Point] other # the other point to compare to. # # @return [TrueClass, FalseClass] def ==(other) self.x == other.x && self.y == other.y end end end
Version data entries
10 entries across 10 versions & 1 rubygems