Class: RVM::Classes::VMClass

Inherits:
Class
  • Object
show all
Defined in:
lib/rvm/classes/class.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Class

#is_true?, #method_missing

Methods included from Plugin

#helper, #included, #plugin_host, #plugin_id, #register_for

Constructor Details

#initialize(parent = nil, initialize_name = "create") ⇒ VMClass

Returns a new instance of VMClass.



17
18
19
20
21
22
23
24
# File 'lib/rvm/classes/class.rb', line 17

def initialize(parent = nil, initialize_name = "create");
  super()
  @initializer = initialize_name
  @functions = {}
  @variables = {}
  @object_functions = {}
  @parent = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RVM::Classes::Class

Instance Attribute Details

#functionsObject (readonly)

Returns the value of attribute functions.



7
8
9
# File 'lib/rvm/classes/class.rb', line 7

def functions
  @functions
end

#initializerObject

Returns the value of attribute initializer.



10
11
12
# File 'lib/rvm/classes/class.rb', line 10

def initializer
  @initializer
end

#object_functionsObject (readonly)

Returns the value of attribute object_functions.



6
7
8
# File 'lib/rvm/classes/class.rb', line 6

def object_functions
  @object_functions
end

#parentObject

Returns the value of attribute parent.



11
12
13
# File 'lib/rvm/classes/class.rb', line 11

def parent
  @parent
end

#variablesObject (readonly)

Returns the value of attribute variables.



9
10
11
# File 'lib/rvm/classes/class.rb', line 9

def variables
  @variables
end

Instance Method Details

#data_typeObject



13
14
15
# File 'lib/rvm/classes/class.rb', line 13

def data_type
  :class
end

#instance(params, env) ⇒ Object



39
40
41
42
43
44
# File 'lib/rvm/classes/class.rb', line 39

def instance params, env
  o = RVM::Classes::Object.new self
  env = RVM::Interpreter::Environment.new({:params => params||[], :locals => @variables, :functions => @functions}, env)
  o.obj_send(@initializer, [], env) if @object_functions[@initializer]
  o
end

#obj_send(method, params, env) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rvm/classes/class.rb', line 26

def obj_send(method, params, env)
  if method == @initializer
    instance params, env
  else
    m = @functions[method] || 
    m = @parent.functions(method) if not m and @parent
    raise "Unknown method #{method} for object #{self}" if not m
    params.unshift self
    env = RVM::Interpreter::Environment.new({:params => params||[], :locals => @variables, :functions => @functions}, env)
    m.call(params, env)
  end
end