Class: Robot

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position: NullPosition.new, arena: NullArena.new) ⇒ Robot

Returns a new instance of Robot.



10
11
12
13
# File 'lib/another_toy_robot/robot.rb', line 10

def initialize(position: NullPosition.new, arena: NullArena.new)
  @position = position
  @arena    = arena
end

Instance Attribute Details

#arenaObject

Returns the value of attribute arena.



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

def arena
  @arena
end

#positionObject (readonly)

Returns the value of attribute position.



8
9
10
# File 'lib/another_toy_robot/robot.rb', line 8

def position
  @position
end

Instance Method Details

#leftObject



23
24
25
# File 'lib/another_toy_robot/robot.rb', line 23

def left
  safely_go_to @position.left
end

#moveObject



19
20
21
# File 'lib/another_toy_robot/robot.rb', line 19

def move
  safely_go_to @position.advance
end

#place(position) ⇒ Object



15
16
17
# File 'lib/another_toy_robot/robot.rb', line 15

def place(position)
  safely_go_to position
end

#reportObject



31
32
33
# File 'lib/another_toy_robot/robot.rb', line 31

def report
  puts @position.to_s
end

#rightObject



27
28
29
# File 'lib/another_toy_robot/robot.rb', line 27

def right
  safely_go_to @position.right
end