Class: Robot::Point

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x:, y:) ⇒ Point

Returns a new instance of Point.



9
10
11
12
# File 'lib/robot/point.rb', line 9

def initialize(x:, y:)
  @x = x
  @y = y
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



7
8
9
# File 'lib/robot/point.rb', line 7

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



7
8
9
# File 'lib/robot/point.rb', line 7

def y
  @y
end

Instance Method Details

#<(other) ⇒ Object



38
39
40
# File 'lib/robot/point.rb', line 38

def <(other)
  x < other.x || y < other.y
end

#==(other) ⇒ Object



30
31
32
# File 'lib/robot/point.rb', line 30

def ==(other)
  x == other.x && y == other.y
end

#>(other) ⇒ Object



34
35
36
# File 'lib/robot/point.rb', line 34

def >(other)
  x > other.x || y > other.y
end

#eastObject



22
23
24
# File 'lib/robot/point.rb', line 22

def east
  Point.new(x: x + 1, y: y)
end

#northObject



14
15
16
# File 'lib/robot/point.rb', line 14

def north
  Point.new(x: x, y: y + 1)
end

#southObject



18
19
20
# File 'lib/robot/point.rb', line 18

def south
  Point.new(x: x, y: y - 1)
end

#to_sObject



42
43
44
# File 'lib/robot/point.rb', line 42

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

#westObject



26
27
28
# File 'lib/robot/point.rb', line 26

def west
  Point.new(x: x - 1, y: y)
end