class Tape
Public Class Methods
new(str=nil)
click to toggle source
# File bin/tm, line 6 def initialize(str=nil) @tape = (str.nil? ? "" : str.dup) @position = 0 end
Public Instance Methods
left()
click to toggle source
# File bin/tm, line 11 def left if @position == 0 @tape.insert(@position, "_") else @position -= 1 end end
read()
click to toggle source
# File bin/tm, line 24 def read ensure_current_position_exists @tape[@position, 1] end
right()
click to toggle source
# File bin/tm, line 19 def right ensure_current_position_exists @position += 1 end
to_s()
click to toggle source
# File bin/tm, line 34 def to_s @tape.sub(/^_+/, '').sub(/_.*/, '') end
write(val)
click to toggle source
# File bin/tm, line 29 def write(val) ensure_current_position_exists @tape[@position] = val end
Private Instance Methods
ensure_current_position_exists()
click to toggle source
# File bin/tm, line 40 def ensure_current_position_exists if @position == @tape.length @tape << "_" end end