Class: Mapleseed::Ring
- Inherits:
-
Object
- Object
- Mapleseed::Ring
- Defined in:
- lib/mapleseed/ring.rb
Overview
base class for whirl command rings
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(interpreter) ⇒ Ring
constructor
initialize the ring.
-
#rotate ⇒ Object
rotate the ring in the given direction.
-
#switch_direction ⇒ Object
change the direction of the ring.
Constructor Details
#initialize(interpreter) ⇒ Ring
initialize the ring
8 9 10 11 12 13 14 |
# File 'lib/mapleseed/ring.rb', line 8 def initialize(interpreter) @position = 0 @value = 0 @direction = 1 @commands = [] @interpreter = interpreter end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
5 6 7 |
# File 'lib/mapleseed/ring.rb', line 5 def commands @commands end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
5 6 7 |
# File 'lib/mapleseed/ring.rb', line 5 def direction @direction end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
5 6 7 |
# File 'lib/mapleseed/ring.rb', line 5 def position @position end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/mapleseed/ring.rb', line 5 def value @value end |
Instance Method Details
#execute ⇒ Object
31 32 33 34 35 |
# File 'lib/mapleseed/ring.rb', line 31 def execute if @position < @commands.length send @commands[@position] end end |
#rotate ⇒ Object
rotate the ring in the given direction
22 23 24 25 26 27 28 29 |
# 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 ⇒ Object
change the direction of the ring
17 18 19 |
# File 'lib/mapleseed/ring.rb', line 17 def switch_direction @direction *= -1 end |