123456789_123456789_123456789_123456789_123456789_

Class: TypeProf::Type::Instance

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: TypeProf::Type
Defined in: lib/typeprof/type.rb

Constant Summary

::TypeProf::Type - Inherited

Builtin, DummySubstitution

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(klass, include_subclasses = false) ⇒ Instance

[ GitHub ]

  
# File '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

Class Method Details

.new_degenerate(instances)

[ GitHub ]

  
# File '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

Instance Attribute Details

#include_subclasses (readonly)

[ GitHub ]

  
# File 'lib/typeprof/type.rb', line 570

attr_reader :klass, :include_subclasses

#klass (readonly)

[ GitHub ]

  
# File 'lib/typeprof/type.rb', line 570

attr_reader :klass, :include_subclasses

Instance Method Details

#consistent?(other) ⇒ Boolean

[ GitHub ]

  
# File '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

[ GitHub ]

  
# File 'lib/typeprof/type.rb', line 572

def inspect
  "I[#{ @klass.inspect }]"
end

#method_dispatch_info

[ GitHub ]

  
# File 'lib/typeprof/type.rb', line 586

def method_dispatch_info
  [@klass, false, @include_subclasses]
end

#screen_name(scratch)

[ GitHub ]

  
# File '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)

[ GitHub ]

  
# File 'lib/typeprof/type.rb', line 602

def substitute(subst, depth)
  Instance.new(@klass.substitute(subst, depth))
end