Class: Kalc::Ast::FunctionCall

Inherits:
Object
  • Object
show all
Defined in:
lib/kalc/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



239
240
241
# File 'lib/kalc/ast.rb', line 239

def name
  @name
end

#variable_listObject (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