Class: Robot::Position
- Inherits:
-
Object
- Object
- Robot::Position
- Defined in:
- lib/robot/position.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#point ⇒ Object
readonly
Returns the value of attribute point.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #east ⇒ Object
-
#initialize(point: Point.new(x: 0, y: 0), direction: Robot::Directions::NORTH) ⇒ Position
constructor
A new instance of Position.
- #left ⇒ Object
- #north ⇒ Object
- #right ⇒ Object
- #south ⇒ Object
- #to_s ⇒ Object
- #west ⇒ Object
Constructor Details
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
7 8 9 |
# File 'lib/robot/position.rb', line 7 def direction @direction end |
#point ⇒ Object (readonly)
Returns the value of attribute point.
7 8 9 |
# File 'lib/robot/position.rb', line 7 def point @point end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 |
# File 'lib/robot/position.rb', line 38 def ==(other) point == other.point && direction == other.direction end |
#east ⇒ Object
22 23 24 |
# File 'lib/robot/position.rb', line 22 def east Position.new(point: point.east, direction: direction) end |
#left ⇒ Object
30 31 32 |
# File 'lib/robot/position.rb', line 30 def left Position.new(point: point, direction: lefts[direction]) end |
#north ⇒ Object
14 15 16 |
# File 'lib/robot/position.rb', line 14 def north Position.new(point: point.north, direction: direction) end |
#right ⇒ Object
34 35 36 |
# File 'lib/robot/position.rb', line 34 def right Position.new(point: point, direction: rights[direction]) end |
#south ⇒ Object
18 19 20 |
# File 'lib/robot/position.rb', line 18 def south Position.new(point: point.south, direction: direction) end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/robot/position.rb', line 42 def to_s "#{point}, #{direction}" end |