class Command::While
Public Class Methods
new(condition_statement)
click to toggle source
# File lib/karel/command/while.rb, line 5 def initialize(condition_statement) @condition_statement = condition_statement @statements = [] end
Public Instance Methods
add_statement(statement)
click to toggle source
# File lib/karel/command/while.rb, line 10 def add_statement(statement) @statements << statement end
execute(compass, location, tokens)
click to toggle source
# File lib/karel/command/while.rb, line 14 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