Class: Sol::RuntimeModel::SolFunction

Inherits:
SolObject
  • Object
show all
Defined in:
lib/sol/runtime/function.rb

Overview

Represents a method defined in the runtime

Instance Attribute Summary

Attributes inherited from SolObject

#ruby_value, #runtime_class

Instance Method Summary collapse

Constructor Details

#initialize(params, body) ⇒ SolFunction

Returns a new instance of SolFunction.



10
11
12
13
14
15
16
# File 'lib/sol/runtime/function.rb', line 10

def initialize(params, body)

  @params = params

  @body = body

end

Instance Method Details

#call(reciever, arguments) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sol/runtime/function.rb', line 18

def call(reciever, arguments)

  # Create a context of evaluation in which the method will execute
  context = Context.new(reciever)

  if @params.class == "NullClass"

    # Assign arguments to local variables
    @params.to_enum.each_with_index do |param, index|

      context.locals[param] = arguments[index]

    end

  end

  return @body.eval(context)

end