class Robot
Constants
- UNPLACED_NOTICE
Attributes
position[R]
Public Class Methods
new(grid)
click to toggle source
# File lib/robot.rb, line 9 def initialize(grid) @grid = grid @position = Position.new(nil, nil, nil) end
Public Instance Methods
move()
click to toggle source
# File lib/robot.rb, line 18 def move update_position @position.advance end
place(position)
click to toggle source
# File lib/robot.rb, line 14 def place(position) update_position position end
placed?()
click to toggle source
# File lib/robot.rb, line 35 def placed? @position.valid? @grid end
report()
click to toggle source
# File lib/robot.rb, line 30 def report return UNPLACED_NOTICE unless placed? @position.to_s end
rotate_left()
click to toggle source
# File lib/robot.rb, line 22 def rotate_left update_position @position.left end
rotate_right()
click to toggle source
# File lib/robot.rb, line 26 def rotate_right update_position @position.right end
Private Instance Methods
update_position(new_position)
click to toggle source
# File lib/robot.rb, line 41 def update_position(new_position) @position = new_position if new_position.valid? @grid end