class EleetScript::EleetScriptClass
Attributes
class_name[RW]
class_vars[RW]
context[RW]
methods[RW]
name[RW]
super_class[R]
Public Class Methods
create(namespace, name, super_class = nil)
click to toggle source
# File lib/lang/runtime/class.rb, line 13 def create(namespace, name, super_class = nil) cls = EleetScriptClass.new(namespace, super_class) cls.name = name cls end
new(namespace, super_class = nil)
click to toggle source
# File lib/lang/runtime/class.rb, line 20 def initialize(namespace, super_class = nil) @methods = MethodHash.new @class_vars = ProcessedKeyHash.new @class_vars.set_key_preprocessor do |key| key[0..1] == '@@' ? key[2..-1] : key end @context = namespace.new_class_context(self, self) @super_class = super_class @ruby_value = self end
Public Instance Methods
call(method_name, arguments = [])
click to toggle source
# File lib/lang/runtime/class.rb, line 32 def call(method_name, arguments = []) method = lookup(method_name.to_s) call_method(method_name, method, arguments) end
class_def(method_name, es_block = nil, &block)
click to toggle source
# File lib/lang/runtime/class.rb, line 83 def class_def(method_name, es_block = nil, &block) method_name = "@@#{method_name}" if block_given? @methods[method_name] = block else @methods[method_name] = es_method end end
def(method_name, es_block = nil, &block)
click to toggle source
# File lib/lang/runtime/class.rb, line 74 def def(method_name, es_block = nil, &block) method_name = method_name.to_s if block_given? @methods[method_name] = block else @methods[method_name] = es_method end end
es_responds_to?(method_name)
click to toggle source
# File lib/lang/runtime/class.rb, line 102 def es_responds_to?(method_name) !lookup(method_name.to_s).nil? end
inspect()
click to toggle source
# File lib/lang/runtime/class.rb, line 110 def inspect to_s[0..-2] + " @methods(#{@methods.keys.join(', ')})>" end
instance_lookup(method_name)
click to toggle source
# File lib/lang/runtime/class.rb, line 46 def instance_lookup(method_name) method = @methods[method_name] if method.nil? && has_super_class? return super_class.instance_lookup(method_name) end method end
lookup(method_name)
click to toggle source
# File lib/lang/runtime/class.rb, line 37 def lookup(method_name) method_name = method_name[0..1] == '@@' ? method_name : "@@#{method_name}" method = @methods[method_name] if method.nil? && has_super_class? return super_class.lookup(method_name) end method end
new(current_context)
click to toggle source
# File lib/lang/runtime/class.rb, line 92 def new(current_context) EleetScriptClassInstance.new(@context, self, current_context.namespace_context) end
new_with_value(value, current_context)
click to toggle source
# File lib/lang/runtime/class.rb, line 96 def new_with_value(value, current_context) EleetScriptClassInstance.new(@context, self, current_context.namespace_context).tap do |instance| instance.ruby_value = value end end
super_call(method_name, arguments = [])
click to toggle source
# File lib/lang/runtime/class.rb, line 54 def super_call(method_name, arguments = []) if super_class == self @context['Errors'].call( :<, @context['String'].new_with_value( "Cannot call super implmentation for #{method_name} if there is no super class", @context ) ) @context['nil'] else method = super_class.lookup(method_name) call_method(method_name, method, arguments) end end
to_s()
click to toggle source
# File lib/lang/runtime/class.rb, line 106 def to_s "<EleetScriptClass \"#{name || 'Unnamed'}\">" end
Private Instance Methods
call_method(method_name, method, arguments)
click to toggle source
# File lib/lang/runtime/class.rb, line 116 def call_method(method_name, method, arguments) if method if method.arity == 3 method.call(self, arguments, @context) else method.call(self, arguments) end else es_method_name = @context['String'].new_with_value(method_name.to_s, @context.namespace_context) call(NO_METHOD, arguments.dup.unshift(es_method_name)) end end
has_super_class?()
click to toggle source
# File lib/lang/runtime/class.rb, line 129 def has_super_class? @super_class || (@super_class.nil? && name != 'Object') end