Class: Basic101::OnGotoStatement
- Defined in:
- lib/basic101/on_goto_statement.rb
Instance Attribute Summary collapse
-
#next_statement ⇒ Object
writeonly
Sets the attribute next_statement.
Attributes inherited from Statement
Instance Method Summary collapse
- #execute(runtime) ⇒ Object
-
#initialize(expression, line_numbers) ⇒ OnGotoStatement
constructor
A new instance of OnGotoStatement.
Methods inherited from Statement
#data_items, #exec, #line_number, #raise_error_with_line_number
Methods included from Identity
Constructor Details
#initialize(expression, line_numbers) ⇒ OnGotoStatement
Returns a new instance of OnGotoStatement.
11 12 13 14 |
# File 'lib/basic101/on_goto_statement.rb', line 11 def initialize(expression, line_numbers) @expression = expression @line_numbers = line_numbers end |
Instance Attribute Details
#next_statement=(value) ⇒ Object (writeonly)
Sets the attribute next_statement
9 10 11 |
# File 'lib/basic101/on_goto_statement.rb', line 9 def next_statement=(value) @next_statement = value end |
Instance Method Details
#execute(runtime) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/basic101/on_goto_statement.rb', line 16 def execute(runtime) index = @expression.eval(runtime).to_i - 1 if (0...@line_numbers.size).include?(index) runtime.goto_line(@line_numbers[index].to_i) end end |