Class: AmberVM::Interpreter::SetClassFunction

Inherits:
Element show all
Defined in:
lib/amber/interpreter.rb

Overview

This sets a funciton on a Class (to be included in its objects)

To define class functions use ObjectContext and define the function normaly, nifty isn’t it?

This object may be subject to removal or change, don’t use it yet.


TODO: Work this over.

Instance Attribute Summary

Attributes inherited from Element

#pos

Instance Method Summary collapse

Constructor Details

#initialize(obj, name, function, pos = nil) ⇒ SetClassFunction

Returns a new instance of SetClassFunction.



205
206
207
208
209
210
# File 'lib/amber/interpreter.rb', line 205

def initialize obj, name, function, pos = nil
  super(pos)
  @object = obj
  @name = name
  @function = function
end

Instance Method Details

#execute(env) ⇒ Object



212
213
214
215
# File 'lib/amber/interpreter.rb', line 212

def execute env
  @object.object_functions[@name.execute(env)] = @function
  @function
end

#optimize(variables = {}) ⇒ Object



217
218
219
220
221
# File 'lib/amber/interpreter.rb', line 217

def optimize variables = {}
  object = @object.optimize variables
  function = @function.optimize variables
  SetClassFunction.new(object, function)
end