Class: Robot
- Inherits:
-
Object
- Object
- Robot
- Defined in:
- lib/robot.rb
Constant Summary collapse
- UNPLACED_NOTICE =
"Robot should be placed first."
Instance Attribute Summary collapse
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
-
#initialize(grid) ⇒ Robot
constructor
A new instance of Robot.
- #move ⇒ Object
- #place(position) ⇒ Object
- #placed? ⇒ Boolean
- #report ⇒ Object
- #rotate_left ⇒ Object
- #rotate_right ⇒ Object
Constructor Details
Instance Attribute Details
#position ⇒ Object (readonly)
Returns the value of attribute position.
5 6 7 |
# File 'lib/robot.rb', line 5 def position @position end |
Instance Method Details
#move ⇒ Object
18 19 20 |
# File 'lib/robot.rb', line 18 def move update_position @position.advance end |
#place(position) ⇒ Object
14 15 16 |
# File 'lib/robot.rb', line 14 def place(position) update_position position end |
#placed? ⇒ Boolean
35 36 37 |
# File 'lib/robot.rb', line 35 def placed? @position.valid? @grid end |
#report ⇒ Object
30 31 32 33 |
# File 'lib/robot.rb', line 30 def report return UNPLACED_NOTICE unless placed? @position.to_s end |
#rotate_left ⇒ Object
22 23 24 |
# File 'lib/robot.rb', line 22 def rotate_left update_position @position.left end |
#rotate_right ⇒ Object
26 27 28 |
# File 'lib/robot.rb', line 26 def rotate_right update_position @position.right end |