Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
practicingruby committed Jan 17, 2012
1 parent b1baa7c commit 5441357
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/turing_tarpit.rb
Expand Up @@ -40,7 +40,8 @@ def initialize(source_text)
end

def next(cell_value)
raise StopIteration if @chars.length == @index
validate_index

element = @chars[@index]

case element
Expand All @@ -51,10 +52,10 @@ def next(cell_value)
element = @chars[@index]
when "]"
if cell_value.zero?
while @chars[@index] == "]"
while element == "]"
consume
element = @chars[@index]
raise StopIteration if @chars.length == @index
validate_index
end
else
jump_back
Expand All @@ -68,6 +69,10 @@ def next(cell_value)
end

private

def validate_index
raise StopIteration if @chars.length == @index
end

def consume
@index += 1
Expand Down

0 comments on commit 5441357

Please sign in to comment.