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.



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

def initialize(name, variable_list)
  @name = name
  @variable_list = variable_list
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



236
237
238
# File 'lib/kalc/ast.rb', line 236

def name
  @name
end

#variable_listObject (readonly)

Returns the value of attribute variable_list.



237
238
239
# File 'lib/kalc/ast.rb', line 237

def variable_list
  @variable_list
end

Instance Method Details

#eval(context) ⇒ Object



244
245
246
247
248
249
250
251
252
# File 'lib/kalc/ast.rb', line 244

def eval(context)
  to_call = context.get_function(@name)
  raise "Unknown function #{@name}" unless to_call

  to_call.call(context, *@variable_list)
rescue ArgumentError
  raise "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