Sha256: d35820a839311120cef4a177d1c4ca58015039db0df3ae1e1fb28b1980fa2307
Contents?: true
Size: 1.01 KB
Versions: 2
Compression:
Stored size: 1.01 KB
Contents
require_relative 'response' module Command class While def initialize(condition_statement) @condition_statement = condition_statement @statements = [] end def add_statement(statement) @statements << statement end def execute(compass, location, tokens) response = @condition_statement.execute(compass, location, tokens) operations_count = response.operations_count while response.return_value response = Batch.new(@statements).execute( response.compass, response.location, response.tokens ) operations_count += response.operations_count response = @condition_statement.execute( response.compass, response.location, response.tokens ) operations_count += response.operations_count end Response.new( compass: response.compass, location: response.location, tokens: response.tokens, operations_count: operations_count ) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
karel-interpreter-0.2.0 | lib/karel/command/while.rb |
karel-interpreter-0.1.0 | lib/karel/command/while.rb |