Class: EleetScript::EleetScriptClassInstance
Instance Attribute Summary collapse
#memory, #ruby_value
Instance Method Summary
collapse
#class?, #eql?, #hash, #instance?, set_is_class, set_is_instance
Constructor Details
#initialize(class_context, runtime_class, namespace_context) ⇒ EleetScriptClassInstance
Returns a new instance of EleetScriptClassInstance.
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/lang/runtime/class_instance.rb', line 6
def initialize(class_context, runtime_class, namespace_context)
@methods = MethodHash.new
@instance_vars = ProcessedKeyHash.new
@instance_vars.set_key_preprocessor do |key|
key[0] == "@" ? key[1..-1] : key
end
@runtime_class = runtime_class
@context = class_context.new_instance_context(self, namespace_context)
@ruby_value = self
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
3
4
5
|
# File 'lib/lang/runtime/class_instance.rb', line 3
def context
@context
end
|
#instance_vars ⇒ Object
Returns the value of attribute instance_vars.
3
4
5
|
# File 'lib/lang/runtime/class_instance.rb', line 3
def instance_vars
@instance_vars
end
|
#methods ⇒ Object
Returns the value of attribute methods.
3
4
5
|
# File 'lib/lang/runtime/class_instance.rb', line 3
def methods
@methods
end
|
#runtime_class ⇒ Object
Returns the value of attribute runtime_class.
3
4
5
|
# File 'lib/lang/runtime/class_instance.rb', line 3
def runtime_class
@runtime_class
end
|
Instance Method Details
#call(method_name, arguments = []) ⇒ Object
21
22
23
24
|
# File 'lib/lang/runtime/class_instance.rb', line 21
def call(method_name, arguments = [])
method = find_method(method_name)
call_method(method_name, method, arguments)
end
|
#class_name ⇒ Object
71
72
73
|
# File 'lib/lang/runtime/class_instance.rb', line 71
def class_name
@runtime_class.name
end
|
#es_responds_to?(method_name) ⇒ Boolean
17
18
19
|
# File 'lib/lang/runtime/class_instance.rb', line 17
def es_responds_to?(method_name)
!find_method(method_name).nil?
end
|
#find_method(method_name) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/lang/runtime/class_instance.rb', line 42
def find_method(method_name)
method = @methods[method_name]
if method.nil?
method = @runtime_class.instance_lookup(method_name.to_s)
end
method
end
|
#inspect ⇒ Object
54
55
56
|
# File 'lib/lang/runtime/class_instance.rb', line 54
def inspect
to_s
end
|
#is_a?(*values) ⇒ Boolean
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/lang/runtime/class_instance.rb', line 58
def is_a?(*values)
names = ["Object", runtime_class.name]
cur_class = runtime_class
while cur_class.super_class.name != "Object"
names << cur_class.super_class.name
cur_class = cur_class.super_class
end
values.each do |value|
return true if names.include?(value)
end
false
end
|
#super_call(method_name, arguments = []) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/lang/runtime/class_instance.rb', line 26
def super_call(method_name, arguments = [])
kls = @runtime_class
super_kls = kls.super_class
if kls == super_kls
str = @context['String'].new_with_value(
"Cannot call super implementation for #{method_name} without a super class",
@context
)
@context['Errors'].call(:<, str)
@context['nil']
else
method = super_kls.instance_lookup(method_name)
call_method(method_name, method, arguments)
end
end
|
#to_s ⇒ Object
50
51
52
|
# File 'lib/lang/runtime/class_instance.rb', line 50
def to_s
"<EleetScriptClassInstance @instance_of=\"#{runtime_class.name || "Unnamed"}\">"
end
|