Class: Direction

Inherits:
Object
  • Object
show all
Defined in:
lib/robotgame/direction.rb

Overview

require “pry”

Class Method Summary collapse

Instance Method Summary collapse

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

.[](name) ⇒ Object



37
38
39
# File 'lib/robotgame/direction.rb', line 37

def self.[](name)
  Direction.const_get(name) if Direction.const_defined?(name)
end

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

#leftObject



13
14
15
# File 'lib/robotgame/direction.rb', line 13

def left
  Direction.const_get(@left)
end

#rightObject



17
18
19
# File 'lib/robotgame/direction.rb', line 17

def right
  Direction.const_get(@right)
end

#to_sObject



9
10
11
# File 'lib/robotgame/direction.rb', line 9

def to_s
  @name
end