Class: Keisan::Functions::While
- Inherits:
-
Keisan::Function
- Object
- Keisan::Function
- Keisan::Functions::While
- Defined in:
- lib/keisan/functions/while.rb
Defined Under Namespace
Classes: WhileLogicalNodeIsNonBoolConstant, WhileLogicalNodeIsNotConstant
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
#differentiate, #unbound_variables
Constructor Details
#initialize ⇒ While
Returns a new instance of While.
7 8 9 |
# File 'lib/keisan/functions/while.rb', line 7 def initialize super("while", 2) end |
Instance Method Details
#evaluate(ast_function, context = nil) ⇒ Object
16 17 18 19 20 |
# File 'lib/keisan/functions/while.rb', line 16 def evaluate(ast_function, context = nil) validate_arguments!(ast_function.children.count) context ||= Keisan::Context.new while_loop(ast_function, context, simplify: false) end |
#simplify(ast_function, context = nil) ⇒ Object
22 23 24 25 26 |
# File 'lib/keisan/functions/while.rb', line 22 def simplify(ast_function, context = nil) validate_arguments!(ast_function.children.count) context ||= Context.new while_loop(ast_function, context, simplify: true) end |
#value(ast_function, context = nil) ⇒ Object
11 12 13 14 |
# File 'lib/keisan/functions/while.rb', line 11 def value(ast_function, context = nil) validate_arguments!(ast_function.children.count) evaluate(ast_function, context) end |