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 213

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 211

attr_reader :ancestors

#params (readonly)

[ GitHub ]

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

attr_reader :params

#type_name (readonly)

[ GitHub ]

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

attr_reader :type_name

Instance Method Details

#apply(args, location:)

[ GitHub ]

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

def apply(args, location:)
  InvalidTypeApplicationError.check!(
    type_name: type_name,
    args: args,
    params: params,
    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