Class: FunctiondefNode

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

Overview

Class for defining functions.

Instance Method Summary collapse

Constructor Details

#initialize(identifier, block, parameters = []) ⇒ FunctiondefNode

Returns a new instance of FunctiondefNode.



108
109
110
111
112
# File 'lib/nodes.rb', line 108

def initialize(identifier, block, parameters = [])
  @identifier = identifier.value
  @parameters = parameters
  @block = block
end

Instance Method Details

#evaluate(scope) ⇒ Object

Saves identifier with code-block and parameters in current scope



115
116
117
118
# File 'lib/nodes.rb', line 115

def evaluate(scope)
  params = @parameters.map {|parameter| parameter.value}
  scope.set_function(@identifier, @block, params)
end