Class: RDGC::Map::Direction

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

Constant Summary collapse

SELF =
self.create(0, 0)
LEFT =
self.create(-1, 0)
RIGHT =
self.create(1, 0)
UPPER =
self.create(0, -1)
BOTTOM =
self.create(0, 1)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



6
7
8
# File 'lib/rdgc/map/direction.rb', line 6

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



6
7
8
# File 'lib/rdgc/map/direction.rb', line 6

def y
  @y
end

Class Method Details

.allObject



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

def self.all
  [LEFT, UPPER, RIGHT, BOTTOM]
end

.eachObject



30
31
32
33
34
35
# File 'lib/rdgc/map/direction.rb', line 30

def self.each
  return to_enum(:each) unless block_given?
  self.all.each do |d|
    yield(d)
  end
end

Instance Method Details

#oppositeObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rdgc/map/direction.rb', line 41

def opposite
  case self
  when LEFT
    RIGHT
  when RIGHT
    LEFT
  when UPPER
    BOTTOM
  when BOTTOM
    UPPER
  when SELF
    SELF
  end
end