Class: TurmaliMethod

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

Instance Method Summary collapse

Constructor Details

#initialize(params, body) ⇒ TurmaliMethod

Returns a new instance of TurmaliMethod.



2
3
4
5
# File 'lib/turmali/runtime/method.rb', line 2

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

Instance Method Details

#call(receiver, arguments) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/turmali/runtime/method.rb', line 7

def call(receiver, arguments)
  context = Context.new(receiver)

  @params.each_with_index do |param, index|
    context.locals[param] = arguments[index]
  end

  @body.eval(context)
end