Class: Toybot::Direction
- Inherits:
-
Object
- Object
- Toybot::Direction
- Defined in:
- lib/toybot/direction.rb
Constant Summary collapse
- DIRECTIONS =
[:north, :east, :south, :west]
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(facing = :north) ⇒ Direction
constructor
A new instance of Direction.
- #rotate_clockwise! ⇒ Object
- #rotate_counter_clockwise! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(facing = :north) ⇒ Direction
6 7 8 |
# File 'lib/toybot/direction.rb', line 6 def initialize facing = :north self.value = facing end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
2 3 4 |
# File 'lib/toybot/direction.rb', line 2 def value @value end |
Instance Method Details
#rotate_clockwise! ⇒ Object
14 15 16 |
# File 'lib/toybot/direction.rb', line 14 def rotate_clockwise! self.value = DIRECTIONS[DIRECTIONS.index(@value) + 1] || DIRECTIONS[0] end |
#rotate_counter_clockwise! ⇒ Object
18 19 20 |
# File 'lib/toybot/direction.rb', line 18 def rotate_counter_clockwise! self.value = DIRECTIONS[DIRECTIONS.index(@value) - 1] end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/toybot/direction.rb', line 22 def to_s @value.to_s end |