123456789_123456789_123456789_123456789_123456789_

Class: RBS::Definition::InstanceAncestors

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/definition.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(type_name:, params:, ancestors:) ⇒ InstanceAncestors

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 234

def initialize(type_name:, params:, ancestors:)
  @type_name = type_name
  @params = params
  @ancestors = ancestors
end

Instance Attribute Details

#ancestors (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 232

attr_reader :ancestors

#params (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 231

attr_reader :params

#type_name (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 230

attr_reader :type_name

Instance Method Details

#apply(args, env:, location:)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 240

def apply(args, env:, location:)
  InvalidTypeApplicationError.check2!(env: env, type_name: type_name, args: args, location: location)

  subst = Substitution.build(params, args)

  ancestors.map do |ancestor|
    case ancestor
    when Ancestor::Instance
      if ancestor.args.empty?
        ancestor
      else
        Ancestor::Instance.new(
          name: ancestor.name,
          args: ancestor.args.map {|type| type.sub(subst) },
          source: ancestor.source
        )
      end
    when Ancestor::Singleton
      ancestor
    end
  end
end