Class: Kalc::Ast::FunctionCall
- Inherits:
-
Object
- Object
- Kalc::Ast::FunctionCall
- Defined in:
- lib/kalc/ast.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#variable_list ⇒ Object
readonly
Returns the value of attribute variable_list.
Instance Method Summary collapse
- #eval(context) ⇒ Object
-
#initialize(name, variable_list) ⇒ FunctionCall
constructor
A new instance of FunctionCall.
Constructor Details
#initialize(name, variable_list) ⇒ FunctionCall
Returns a new instance of FunctionCall.
242 243 244 245 |
# File 'lib/kalc/ast.rb', line 242 def initialize(name, variable_list) @name = name @variable_list = variable_list end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
239 240 241 |
# File 'lib/kalc/ast.rb', line 239 def name @name end |
#variable_list ⇒ Object (readonly)
Returns the value of attribute variable_list.
240 241 242 |
# File 'lib/kalc/ast.rb', line 240 def variable_list @variable_list end |
Instance Method Details
#eval(context) ⇒ Object
247 248 249 250 251 252 253 254 |
# File 'lib/kalc/ast.rb', line 247 def eval(context) to_call = context.get_function(@name) fail "Unknown function #{@name}" unless to_call to_call.call(context, *@variable_list) rescue ArgumentError fail "Argument Error. Function #{@name} was called with #{@variable_list.count} parameters. " + "It needs at least #{to_call.parameters.select{|a| a.first == :req}.count - 1 } parameters" end |