class TypeProf::Core::Type::Array - typeprof: Ruby Standard Library Documentation

# class TypeProf::Core::Type::Array

### Attributes

elems[R]

### Public Class Methods

new(genv, elems, base_type) click to toggle source

: (`GlobalEnv`, ::Array[Vertex], `Instance`) -> void

    # File typeprof-0.30.1/lib/typeprof/core/type.rb, line 158
    def initialize(genv, elems, base_type)
      @elems = elems
      @base_type = base_type
      raise unless base_type.is_a?(Instance)
    end

### Public Instance Methods

base_type(genv) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/type.rb, line 203
    def base_type(genv)
      @base_type
    end

check_match(genv, changes, vtx) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/type.rb, line 207
    def check_match(genv, changes, vtx)
      vtx.each_type do |other_ty|
        if other_ty.is_a?(Array)
          if @elems.size == other_ty.elems.size
            match = true
            @elems.zip(other_ty.elems) do |elem, other_elem|
              unless elem.check_match(genv, changes, other_elem)
                match = false
                break
              end
            end
            return true if match
          end
        end
      end
      @base_type.check_match(genv, changes, vtx)
    end

get_elem(genv, idx = nil) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/type.rb, line 166
    def get_elem(genv, idx = nil)
      if idx && @elems
        @elems[idx] || Source.new(genv.nil_type)
      else
        @base_type.args.first
      end
    end

show() click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/type.rb, line 225
    def show
      if @elems
        "[#{ @elems.map {|e| Type.strip_parens(e.show) }.join(", ") }]"
      else
        "#{ @base_type.mod.show_cpath }[#{ Type.strip_parens(@unified_elem.show) }]"
      end
    end

splat_assign(genv, lefts, rest_elem, rights) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/type.rb, line 174
    def splat_assign(genv, lefts, rest_elem, rights)
      edges = []
      state = :left
      j = nil
      @elems.each_with_index do |elem, i|
        case state
        when :left
          if i < lefts.size
            edges << [elem, lefts[i]]
          else
            break unless rest_elem
            state = :rest
            redo
          end
        when :rest
          if @elems.size - i > rights.size
            edges << [elem, rest_elem]
          else
            state = :right
            j = i
            redo
          end
        when :right
          edges << [elem, rights[i - j]]
        end
      end
      edges
    end