class TypeProf::Type::Instance
Attributes
include_subclasses[R]
klass[R]
Public Class Methods
new(klass, include_subclasses=false)
click to toggle source
# 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
new_degenerate(instances)
click to toggle source
# 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
Public Instance Methods
consistent?(other)
click to toggle source
# 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
inspect()
click to toggle source
# File typeprof-0.21.2/lib/typeprof/type.rb, line 572 def inspect "I[#{ @klass.inspect }]" end
method_dispatch_info()
click to toggle source
# File typeprof-0.21.2/lib/typeprof/type.rb, line 586 def method_dispatch_info [@klass, false, @include_subclasses] end
screen_name(scratch)
click to toggle source
# 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
substitute(subst, depth)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/type.rb, line 602 def substitute(subst, depth) Instance.new(@klass.substitute(subst, depth)) end