Class: RBS::Inline::AST::Members::RubyMixin

Inherits:
RubyBase show all
Includes:
Declarations::ConstantUtil
Defined in:
lib/rbs/inline/ast/members.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#location

Instance Method Summary collapse

Methods included from Declarations::ConstantUtil

#type_name, #value_node

Methods inherited from Base

#start_line

Constructor Details

#initialize(node, comments, application) ⇒ RubyMixin

Returns a new instance of RubyMixin.



359
360
361
362
363
364
365
# File 'lib/rbs/inline/ast/members.rb', line 359

def initialize(node, comments, application)
  super(node.location)

  @node = node
  @comments = comments
  @application = application
end

Instance Attribute Details

#applicationObject (readonly)

Possible following type application annotation



353
354
355
# File 'lib/rbs/inline/ast/members.rb', line 353

def application
  @application
end

#commentsObject (readonly)

Comments attached to the call node



350
351
352
# File 'lib/rbs/inline/ast/members.rb', line 350

def comments
  @comments
end

#nodeObject (readonly)

CallNode that calls ‘include`, `prepend`, and `extend` method



347
348
349
# File 'lib/rbs/inline/ast/members.rb', line 347

def node
  @node
end

Instance Method Details

#rbsObject



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/rbs/inline/ast/members.rb', line 371

def rbs
  return unless node.arguments
  return unless node.arguments.arguments.size == 1

  arg = node.arguments.arguments[0] || raise
  type_name = type_name(arg)
  return unless type_name

  args = [] #: Array[Types::t]
  if application
    if application.types
      args.concat(application.types)
    end
  end

  case node.name
  when :include
    RBS::AST::Members::Include.new(
      name: type_name,
      args: args,
      annotations: [],
      location: nil,
      comment: nil
    )
  when :extend
    RBS::AST::Members::Extend.new(
      name: type_name,
      args: args,
      annotations: [],
      location: nil,
      comment: nil
    )
  when :prepend
    RBS::AST::Members::Prepend.new(
      name: type_name,
      args: args,
      annotations: [],
      location: nil,
      comment: nil
    )
  end
end