Class: Basic101::IfStatement
- Defined in:
- lib/basic101/if_statement.rb
Instance Attribute Summary collapse
-
#else_statement ⇒ Object
writeonly
Sets the attribute else_statement.
Attributes inherited from Statement
Instance Method Summary collapse
- #end_statement=(statement) ⇒ Object
- #execute(runtime) ⇒ Object
-
#initialize(condition) ⇒ IfStatement
constructor
A new instance of IfStatement.
Methods inherited from Statement
#data_items, #exec, #line_number, #raise_error_with_line_number
Methods included from Identity
Constructor Details
#initialize(condition) ⇒ IfStatement
Returns a new instance of IfStatement.
11 12 13 14 |
# File 'lib/basic101/if_statement.rb', line 11 def initialize(condition) @condition = condition @true_statement = nil end |
Instance Attribute Details
#else_statement=(value) ⇒ Object (writeonly)
Sets the attribute else_statement
9 10 11 |
# File 'lib/basic101/if_statement.rb', line 9 def else_statement=(value) @else_statement = value end |
Instance Method Details
#end_statement=(statement) ⇒ Object
16 17 18 |
# File 'lib/basic101/if_statement.rb', line 16 def end_statement=(statement) @else_statement.end_statement = statement end |
#execute(runtime) ⇒ Object
20 21 22 23 24 |
# File 'lib/basic101/if_statement.rb', line 20 def execute(runtime) if @condition.eval(runtime).to_f == 0 @else_statement.goto_following_statement(runtime) end end |