class MarsRover::Rover
Attributes
direction[RW]
plateau[RW]
x[RW]
y[RW]
Public Class Methods
new(x, y, direction, plateau)
click to toggle source
# File lib/mars_rover/rover.rb, line 12 def initialize(x, y, direction, plateau) self.x = x self.y = y self.direction = direction self.plateau = plateau raise RoverError unless valid_position? end
Public Instance Methods
move()
click to toggle source
# File lib/mars_rover/rover.rb, line 29 def move MarsRover::Position.move(self) end
run_command(command)
click to toggle source
# File lib/mars_rover/rover.rb, line 33 def run_command(command) case command when 'L' turn_left when 'R' turn_right when 'M' move end end
turn_left()
click to toggle source
# File lib/mars_rover/rover.rb, line 25 def turn_left MarsRover::Direction.turn_left(self) end
turn_right()
click to toggle source
# File lib/mars_rover/rover.rb, line 21 def turn_right MarsRover::Direction.turn_right(self) end
Private Instance Methods
valid_position?()
click to toggle source
# File lib/mars_rover/rover.rb, line 45 def valid_position? x <= plateau.x_upper_limit && x >= plateau.x_lower_limit && y <= plateau.y_upper_limit && y >= plateau.y_lower_limit end