Class: Robot
- Inherits:
-
Object
- Object
- Robot
- Defined in:
- lib/another_toy_robot/robot.rb
Instance Attribute Summary collapse
-
#arena ⇒ Object
Returns the value of attribute arena.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
-
#initialize(position: NullPosition.new, arena: NullArena.new) ⇒ Robot
constructor
A new instance of Robot.
- #left ⇒ Object
- #move ⇒ Object
- #place(position) ⇒ Object
- #report ⇒ Object
- #right ⇒ Object
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
#arena ⇒ Object
Returns the value of attribute arena.
7 8 9 |
# File 'lib/another_toy_robot/robot.rb', line 7 def arena @arena end |
#position ⇒ Object (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
#left ⇒ Object
23 24 25 |
# File 'lib/another_toy_robot/robot.rb', line 23 def left safely_go_to @position.left end |
#move ⇒ Object
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 |
#report ⇒ Object
31 32 33 |
# File 'lib/another_toy_robot/robot.rb', line 31 def report puts @position.to_s end |
#right ⇒ Object
27 28 29 |
# File 'lib/another_toy_robot/robot.rb', line 27 def right safely_go_to @position.right end |