rubyx/lib/boot/boot_class.rb

51 lines
1.4 KiB
Ruby
Raw Normal View History

2014-06-03 19:47:06 +02:00
require_relative "meta_class"
2014-06-13 22:51:53 +02:00
module Boot
# class is mainly a list of methods with a name (for now)
# layout of object is seperated into Layout
2014-06-26 16:52:15 +02:00
class BootClass < Virtual::ObjectConstant
def initialize name , scope , super_class = :Object
2014-06-03 19:47:06 +02:00
super()
@scope = scope
# class methods
@methods = []
@name = name.to_sym
2014-06-03 19:47:06 +02:00
@super_class = super_class
@meta_class = MetaClass.new(self)
end
attr_reader :name , :methods , :meta_class , :context , :super_class
def add_method method
raise "not a method #{method}" unless method.is_a? Virtual::Method
raise "syserr " unless method.name.is_a? Symbol
@methods << method
end
def get_method fname
fname = fname.to_sym
f = @methods.detect{ |f| f.name == fname }
names = @methods.collect{|f| f.name }
f
end
# get the method and if not found, try superclasses. raise error if not found
def resolve_method name
fun = get_method name
unless fun or name == :Object
2014-06-03 19:47:06 +02:00
supr = @context.object_space.get_or_create_class(@super_class)
fun = supr.get_method name
puts "#{supr.methods.collect(&:name)} for #{name} GOT #{fun.class}" if name == :index_of
end
2014-06-13 22:41:45 +02:00
raise "Method not found :#{name}, for #{inspect}" unless fun
fun
end
def inspect
"BootClass #{@name} < #{@super_class}:#{@methods.collect(&:name)}"
end
def to_s
inspect
end
end
end