Class: MarsRover::Rover
- Inherits:
-
Object
- Object
- MarsRover::Rover
- Defined in:
- lib/mars_rover/rover.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#plateau ⇒ Object
Returns the value of attribute plateau.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(x, y, direction, plateau) ⇒ Rover
constructor
A new instance of Rover.
- #move ⇒ Object
- #run_command(command) ⇒ Object
- #turn_left ⇒ Object
- #turn_right ⇒ Object
Constructor Details
#initialize(x, y, direction, plateau) ⇒ Rover
Returns a new instance of Rover.
12 13 14 15 16 17 18 19 |
# 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 |
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
10 11 12 |
# File 'lib/mars_rover/rover.rb', line 10 def direction @direction end |
#plateau ⇒ Object
Returns the value of attribute plateau.
10 11 12 |
# File 'lib/mars_rover/rover.rb', line 10 def plateau @plateau end |
#x ⇒ Object
Returns the value of attribute x.
10 11 12 |
# File 'lib/mars_rover/rover.rb', line 10 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
10 11 12 |
# File 'lib/mars_rover/rover.rb', line 10 def y @y end |
Instance Method Details
#move ⇒ Object
29 30 31 |
# File 'lib/mars_rover/rover.rb', line 29 def move MarsRover::Position.move(self) end |
#run_command(command) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# 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 ⇒ Object
25 26 27 |
# File 'lib/mars_rover/rover.rb', line 25 def turn_left MarsRover::Direction.turn_left(self) end |
#turn_right ⇒ Object
21 22 23 |
# File 'lib/mars_rover/rover.rb', line 21 def turn_right MarsRover::Direction.turn_right(self) end |