Class: BoardGameGrid::Point
- Inherits:
-
Object
- Object
- BoardGameGrid::Point
- Defined in:
- lib/board_game_grid/point.rb
Overview
Point
A point with an x and y co-ordinates
Instance Attribute Summary collapse
-
#x ⇒ Fixnum
readonly
The x co-ordinate.
-
#y ⇒ Fixnum
readonly
The y co-ordinate.
Instance Method Summary collapse
-
#+(other) ⇒ Point
Add a point to another point by adding their co-ordinates and returning a new point.
-
#==(other) ⇒ TrueClass, FalseClass
Check if popints are equal by seeing if their co-ordinates are equal.
-
#initialize(x, y) ⇒ Point
constructor
New objects can be instantiated with.
Constructor Details
#initialize(x, y) ⇒ Point
New objects can be instantiated with
Example:
# Instantiates a new Point
BoardGameGrid::Point.new({
x: 1,
y: 1
})
22 23 24 |
# File 'lib/board_game_grid/point.rb', line 22 def initialize(x, y) @x, @y = x, y end |
Instance Attribute Details
#x ⇒ Fixnum (readonly)
Returns the x co-ordinate.
27 28 29 |
# File 'lib/board_game_grid/point.rb', line 27 def x @x end |
#y ⇒ Fixnum (readonly)
Returns the y co-ordinate.
30 31 32 |
# File 'lib/board_game_grid/point.rb', line 30 def y @y end |
Instance Method Details
#+(other) ⇒ Point
Add a point to another point by adding their co-ordinates and returning a new point.
38 39 40 |
# File 'lib/board_game_grid/point.rb', line 38 def +(other) self.class.new(self.x + other.x, self.y + other.y) end |
#==(other) ⇒ TrueClass, FalseClass
Check if popints are equal by seeing if their co-ordinates are equal.
48 49 50 |
# File 'lib/board_game_grid/point.rb', line 48 def ==(other) self.x == other.x && self.y == other.y end |