Class: TwoDGridLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/two_d_grid_location.rb

Overview

TwoDGridLocation exibits an x,y,cost location

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject

Returns the value of attribute x.



3
4
5
# File 'lib/two_d_grid_location.rb', line 3

def x
  @x
end

#yObject

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_sObject



25
26
27
# File 'lib/two_d_grid_location.rb', line 25

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