rubyx/lib/virtual/type.rb

37 lines
770 B
Ruby
Raw Normal View History

module Virtual
2015-09-27 13:07:02 +02:00
# Integer and (Object) References are the main derived classes, but float will come.
class Type
def == other
return false unless other.class == self.class
return true
end
2015-09-23 17:35:37 +02:00
# map from a type sym (currently :int/:ref) to a class of subtype of Type
2015-09-27 13:07:02 +02:00
# TODO needs to be made extensible in a defined way.
2015-09-23 17:35:37 +02:00
def self.from_sym type
case type
when :int
Virtual::Integer
when :ref
Virtual::Reference
else
raise "No type maps to:#{type}"
end
end
end
class Integer < Type
end
class Reference < Type
# possibly unknown value, but known class (as in methods)
def initialize clazz = nil
@of_class = clazz
end
attr_reader :of_class
end
end