Class: Brainfuck::Runtime
- Inherits:
-
Object
- Object
- Brainfuck::Runtime
- Defined in:
- lib/lang/runtime.rb
Instance Method Summary collapse
-
#initialize ⇒ Runtime
constructor
A new instance of Runtime.
- #mutate(how) ⇒ Object
- #shift(direction) ⇒ Object
- #value ⇒ Object
- #value=(value) ⇒ Object
Constructor Details
#initialize ⇒ Runtime
Returns a new instance of Runtime.
3 4 5 6 |
# File 'lib/lang/runtime.rb', line 3 def initialize @cells = [0] @current_cell = 0 end |
Instance Method Details
#mutate(how) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/lang/runtime.rb', line 23 def mutate(how) case how when :incr @cells[@current_cell] += 1 when :decr @cells[@current_cell] -= 1 end end |
#shift(direction) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lang/runtime.rb', line 8 def shift(direction) case direction when :right @current_cell += 1 if @current_cell > @cells.length - 1 @cells << 0 end when :left @current_cell -= 1 if @current_cell < 0 @current_cell = 0 end end end |
#value ⇒ Object
32 33 34 |
# File 'lib/lang/runtime.rb', line 32 def value @cells[@current_cell] end |
#value=(value) ⇒ Object
36 37 38 |
# File 'lib/lang/runtime.rb', line 36 def value=(value) @cells[@current_cell] = value end |