Class: Keisan::Functions::ToH
- Inherits:
-
Keisan::Function
- Object
- Keisan::Function
- Keisan::Functions::ToH
- Defined in:
- lib/keisan/functions/to_h.rb
Instance Attribute Summary
Attributes inherited from Keisan::Function
Instance Method Summary collapse
- #evaluate(ast_function, context = nil) ⇒ Object
-
#initialize ⇒ ToH
constructor
A new instance of ToH.
- #simplify(ast_function, context = nil) ⇒ Object
- #value(ast_function, context = nil) ⇒ Object
Methods inherited from Keisan::Function
Constructor Details
#initialize ⇒ ToH
Returns a new instance of ToH.
4 5 6 |
# File 'lib/keisan/functions/to_h.rb', line 4 def initialize super("to_h", 1) end |
Instance Method Details
#evaluate(ast_function, context = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/keisan/functions/to_h.rb', line 13 def evaluate(ast_function, context = nil) validate_arguments!(ast_function.children.count) context ||= Context.new child = ast_function.children[0].simplify(context) case child when AST::List AST::Hash.new(child.children) when AST::Hash child else raise Exceptions::InvalidFunctionError.new("Cannot call to_h on a #{child.class}") end end |
#simplify(ast_function, context = nil) ⇒ Object
29 30 31 |
# File 'lib/keisan/functions/to_h.rb', line 29 def simplify(ast_function, context = nil) evaluate(ast_function, context) end |
#value(ast_function, context = nil) ⇒ Object
8 9 10 11 |
# File 'lib/keisan/functions/to_h.rb', line 8 def value(ast_function, context = nil) validate_arguments!(ast_function.children.count) evaluate(ast_function, context).value(context) end |