Class: EleetScript::EleetScriptMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/lang/runtime/method.rb

Instance Method Summary collapse

Constructor Details

#initialize(params, body, lambda_context = nil) ⇒ EleetScriptMethod

Returns a new instance of EleetScriptMethod.



3
4
5
6
7
# File 'lib/lang/runtime/method.rb', line 3

def initialize(params, body, lambda_context = nil)
  @params = params
  @body = body
  @lambda_context = lambda_context
end

Instance Method Details

#arityObject



28
29
30
# File 'lib/lang/runtime/method.rb', line 28

def arity
  3
end

#call(receiver, arguments, parent_context) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lang/runtime/method.rb', line 9

def call(receiver, arguments, parent_context)
  context = parent_context.new_method_context(@lambda_context)

  context["lambda?"] = context["false"]
  @params.each_with_index do |param, index|
    arg = arguments[index]
    next unless arg
    context[param] = arg
  end
  if arguments.length > 0 && arguments.last.is_a?("Lambda")
    context["lambda?"] = context["true"]
    context["lambda"] = arguments.last
  end

  context["arguments"] = context["List"].call(:new, arguments)

  @body.eval(context)
end