# File typeprof-0.21.2/lib/typeprof/type.rb, line 537
def initialize(klass, include_subclasses=false)
raise unless klass
raise if klass == Type.any
raise if klass.is_a?(Type::Instance)
raise if klass.is_a?(Type::Union)
@klass = klass
@include_subclasses = include_subclasses
end
# File typeprof-0.21.2/lib/typeprof/type.rb, line 546
def self.new_degenerate(instances)
klass = instances.first.klass
ancestors = []
ancestor_idxs = {}
while klass != :__root__
ancestor_idxs[klass] = ancestors.size
ancestors << klass
klass = klass.superclass
end
common_superclass = nil
instances[1..].each do |instance|
klass = instance.klass
while !ancestor_idxs[klass]
klass = klass.superclass
end
common_superclass = klass
ancestor_idxs[klass].times do |i|
ancestor_idxs.delete(ancestors[i])
ancestors[i] = nil
end
end
new(common_superclass, true)
end
# File typeprof-0.21.2/lib/typeprof/type.rb, line 590
def consistent?(other)
case other
when Type::Instance
@klass.consistent?(other.klass)
when Type::Class
return true if @klass == Type::Builtin[:obj] || @klass == Type::Builtin[:class] || @klass == Type::Builtin[:module]
return false
else
false
end
end
# File typeprof-0.21.2/lib/typeprof/type.rb, line 572
def inspect
"I[#{ @klass.inspect }]"
end
# File typeprof-0.21.2/lib/typeprof/type.rb, line 586
def method_dispatch_info
[@klass, false, @include_subclasses]
end
# File typeprof-0.21.2/lib/typeprof/type.rb, line 576
def screen_name(scratch)
case @klass
when Type::Builtin[:nil] then "nil"
when Type::Builtin[:true] then "true"
when Type::Builtin[:false] then "false"
else
scratch.get_class_name(@klass) + (@include_subclasses ? "" : "")
end
end