Sha256: e474deb52ab493fdfc5cef68152b2e3584661b68d9d4f84d4cbed09a0a05e43b
Contents?: true
Size: 742 Bytes
Versions: 2
Compression:
Stored size: 742 Bytes
Contents
module JustCheckers # = Point # # A point with an x and y co-ordinates class Point # New objects can be instantiated with # # * +x+ - x co-ordinate # * +y+ - y co-ordinate # # ==== Example: # # Instantiates a new Point # JustCheckers::Point.new({ # x: 1, # y: 1 # }) def initialize(x, y) @x, @y = x, y end attr_reader :x, :y # add a point to another point by adding their co-ordinates and returning a new point. def +(other) self.class.new(self.x + other.x, self.y + other.y) end # check if points are equal by seeing if their co-ordinates are equal. def ==(other) self.x == other.x && self.y == other.y end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
just_checkers-0.1.1 | lib/just_checkers/point.rb |
just_checkers-0.1.0 | lib/just_checkers/point.rb |