Class: TwoDGridLocation
- Inherits:
-
Object
- Object
- TwoDGridLocation
- Defined in:
- lib/two_d_grid_location.rb
Overview
TwoDGridLocation exibits an x,y,cost location
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #<=>(b) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(x, y) ⇒ TwoDGridLocation
constructor
A new instance of TwoDGridLocation.
- #to_s ⇒ Object
Constructor Details
#initialize(x, y) ⇒ TwoDGridLocation
Returns a new instance of TwoDGridLocation.
4 |
# File 'lib/two_d_grid_location.rb', line 4 def initialize(x,y);@x=x;@y=y;end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/two_d_grid_location.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/two_d_grid_location.rb', line 3 def y @y end |
Instance Method Details
#<=>(b) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/two_d_grid_location.rb', line 9 def <=>(b) if @x < b.x -1 elsif @x > b.x 1 else if @y < b.y -1 elsif @y > b.y 1 else 0 end end end |
#==(other) ⇒ Object
5 6 7 |
# File 'lib/two_d_grid_location.rb', line 5 def ==(other) @x == other.x and @y == other.y end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/two_d_grid_location.rb', line 25 def to_s "#{@x},#{@y}" end |