class Mapleseed::Ring
base class for whirl command rings
Attributes
commands[R]
direction[R]
position[R]
value[R]
Public Class Methods
new(interpreter)
click to toggle source
initialize the ring
# File lib/mapleseed/ring.rb, line 8 def initialize(interpreter) @position = 0 @value = 0 @direction = 1 @commands = [] @interpreter = interpreter end
Public Instance Methods
execute()
click to toggle source
# File lib/mapleseed/ring.rb, line 31 def execute if @position < @commands.length send @commands[@position] end end
rotate()
click to toggle source
rotate the ring in the given direction
# File lib/mapleseed/ring.rb, line 22 def rotate @position += @direction if @position == @commands.length @position = 0 elsif @position == -1 @position = @commands.length - 1 end end
switch_direction()
click to toggle source
change the direction of the ring
# File lib/mapleseed/ring.rb, line 17 def switch_direction @direction *= -1 end