Class: RBS::Definition::InstanceAncestors

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/definition.rb,
sig/definition.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_name:, params:, ancestors:) ⇒ InstanceAncestors

Returns a new instance of InstanceAncestors.

Parameters:

  • type_name: (TypeName)
  • params: (Array[Symbol])
  • ancestors: (Array[Ancestor::t])


254
255
256
257
258
# File 'lib/rbs/definition.rb', line 254

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

Instance Attribute Details

#ancestorsArray[Ancestor::t] (readonly)

Returns the value of attribute ancestors.

Returns:

  • (Array[Ancestor::t])


252
253
254
# File 'lib/rbs/definition.rb', line 252

def ancestors
  @ancestors
end

#paramsArray[Symbol] (readonly)

Returns the value of attribute params.

Returns:

  • (Array[Symbol])


251
252
253
# File 'lib/rbs/definition.rb', line 251

def params
  @params
end

#type_nameTypeName (readonly)

Returns the value of attribute type_name.

Returns:



250
251
252
# File 'lib/rbs/definition.rb', line 250

def type_name
  @type_name
end

Instance Method Details

#apply(args, env:, location:) ⇒ Array[Ancestor::t]

Parameters:

Returns:

  • (Array[Ancestor::t])


260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/rbs/definition.rb', line 260

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