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.



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

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



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

def application
  @application
end

#commentsObject (readonly)

Comments attached to the call node



343
344
345
# File 'lib/rbs/inline/ast/members.rb', line 343

def comments
  @comments
end

#nodeObject (readonly)

CallNode that calls include, prepend, and extend method



340
341
342
# File 'lib/rbs/inline/ast/members.rb', line 340

def node
  @node
end

Instance Method Details

#rbsObject



364
365
366
367
368
369
370
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
# File 'lib/rbs/inline/ast/members.rb', line 364

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