Class: Keisan::Functions::While
- Inherits:
-
Keisan::Function
- Object
- Keisan::Function
- Keisan::Functions::While
- Defined in:
- lib/keisan/functions/while.rb
Instance Attribute Summary
Attributes inherited from Keisan::Function
Instance Method Summary collapse
- #evaluate(ast_function, context = nil) ⇒ Object
-
#initialize ⇒ While
constructor
A new instance of While.
- #simplify(ast_function, context = nil) ⇒ Object
- #value(ast_function, context = nil) ⇒ Object
Methods inherited from Keisan::Function
Constructor Details
#initialize ⇒ While
Returns a new instance of While.
4 5 6 |
# File 'lib/keisan/functions/while.rb', line 4 def initialize super("while", 2) end |
Instance Method Details
#evaluate(ast_function, context = nil) ⇒ Object
13 14 15 16 17 |
# File 'lib/keisan/functions/while.rb', line 13 def evaluate(ast_function, context = nil) validate_arguments!(ast_function.children.count) context ||= Keisan::Context.new simplify(ast_function, context) end |
#simplify(ast_function, context = nil) ⇒ Object
19 20 21 22 23 |
# File 'lib/keisan/functions/while.rb', line 19 def simplify(ast_function, context = nil) validate_arguments!(ast_function.children.count) context ||= Context.new while_loop(ast_function.children[0], ast_function.children[1], context) end |
#value(ast_function, context = nil) ⇒ Object
8 9 10 11 |
# File 'lib/keisan/functions/while.rb', line 8 def value(ast_function, context = nil) validate_arguments!(ast_function.children.count) evaluate(ast_function, context) end |