Class: Position
- Inherits:
-
Object
- Object
- Position
- Defined in:
- lib/another_toy_robot/position.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#x_coord ⇒ Object
readonly
Returns the value of attribute x_coord.
-
#y_coord ⇒ Object
readonly
Returns the value of attribute y_coord.
Instance Method Summary collapse
- #advance ⇒ Object
-
#initialize(x_coord: 0, y_coord: 0, direction: North) ⇒ Position
constructor
A new instance of Position.
- #left ⇒ Object
- #right ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
4 5 6 |
# File 'lib/another_toy_robot/position.rb', line 4 def direction @direction end |
#x_coord ⇒ Object (readonly)
Returns the value of attribute x_coord.
4 5 6 |
# File 'lib/another_toy_robot/position.rb', line 4 def x_coord @x_coord end |
#y_coord ⇒ Object (readonly)
Returns the value of attribute y_coord.
4 5 6 |
# File 'lib/another_toy_robot/position.rb', line 4 def y_coord @y_coord end |
Instance Method Details
#advance ⇒ Object
12 13 14 15 |
# File 'lib/another_toy_robot/position.rb', line 12 def advance new_position(x_coord: @x_coord + @direction::X_DISPLACEMENT, y_coord: @y_coord + @direction::Y_DISPLACEMENT) end |
#left ⇒ Object
17 18 19 |
# File 'lib/another_toy_robot/position.rb', line 17 def left new_position direction: @direction.left end |
#right ⇒ Object
21 22 23 |
# File 'lib/another_toy_robot/position.rb', line 21 def right new_position direction: @direction.right end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/another_toy_robot/position.rb', line 25 def to_s "#{@x_coord}, #{@y_coord}, #{@direction}" end |