Class: RBS::Definition::InstanceAncestors

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of InstanceAncestors.



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

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

Instance Attribute Details

#ancestorsObject (readonly)

Returns the value of attribute ancestors.



247
248
249
# File 'lib/rbs/definition.rb', line 247

def ancestors
  @ancestors
end

#paramsObject (readonly)

Returns the value of attribute params.



246
247
248
# File 'lib/rbs/definition.rb', line 246

def params
  @params
end

#type_nameObject (readonly)

Returns the value of attribute type_name.



245
246
247
# File 'lib/rbs/definition.rb', line 245

def type_name
  @type_name
end

Instance Method Details

#apply(args, env:, location:) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/rbs/definition.rb', line 255

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