Class: Direction
- Inherits:
-
Object
- Object
- Direction
- Defined in:
- lib/robotgame/direction.rb
Overview
require “pry”
Class Method Summary collapse
Instance Method Summary collapse
- #advance(x, y) ⇒ Object
-
#initialize(sym, dx, dy, left, right) ⇒ Direction
constructor
A new instance of Direction.
- #left ⇒ Object
- #right ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(sym, dx, dy, left, right) ⇒ Direction
Returns a new instance of Direction.
4 5 6 7 |
# File 'lib/robotgame/direction.rb', line 4 def initialize(sym, dx, dy, left, right) @name, @dx, @dy, @left, @right = sym.to_s, dx, dy, left, right #binding.pry end |
Class Method Details
Instance Method Details
#advance(x, y) ⇒ Object
21 22 23 |
# File 'lib/robotgame/direction.rb', line 21 def advance(x, y) [x + @dx, y + @dy] end |
#left ⇒ Object
13 14 15 |
# File 'lib/robotgame/direction.rb', line 13 def left Direction.const_get(@left) end |
#right ⇒ Object
17 18 19 |
# File 'lib/robotgame/direction.rb', line 17 def right Direction.const_get(@right) end |
#to_s ⇒ Object
9 10 11 |
# File 'lib/robotgame/direction.rb', line 9 def to_s @name end |