Class: RBI::Mixin

Inherits:
NodeWithComments show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/rbi/model.rb,
lib/rbi/printer.rb,
lib/rbi/rewriters/merge_trees.rb

Overview

Mixins

Direct Known Subclasses

Extend, Include, MixesInClassMethods

Instance Attribute Summary collapse

Attributes inherited from NodeWithComments

#comments

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from NodeWithComments

#annotations, #merge_with, #oneline?

Methods inherited from Node

#detach, #group_kind, #merge_with, #oneline?, #parent_conflict_tree, #parent_scope, #print, #print_blank_line_before, #replace, #string

Constructor Details

#initialize(name, names, loc: nil, comments: []) ⇒ Mixin

Returns a new instance of Mixin.



779
780
781
782
# File 'lib/rbi/model.rb', line 779

def initialize(name, names, loc: nil, comments: [])
  super(loc: loc, comments: comments)
  @names = T.let([name, *names], T::Array[String])
end

Instance Attribute Details

#namesObject

Returns the value of attribute names.



769
770
771
# File 'lib/rbi/model.rb', line 769

def names
  @names
end

Instance Method Details

#accept_printer(v) ⇒ Object



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/rbi/printer.rb', line 528

def accept_printer(v)
  print_blank_line_before(v)

  v.printl("# #{loc}") if loc && v.print_locs
  v.visit_all(comments)
  case self
  when Include
    v.printt("include")
  when Extend
    v.printt("extend")
  when MixesInClassMethods
    v.printt("mixes_in_class_methods")
  end
  v.printn(" #{names.join(", ")}")
end

#compatible_with?(other) ⇒ Boolean

Returns:

  • (Boolean)


474
475
476
# File 'lib/rbi/rewriters/merge_trees.rb', line 474

def compatible_with?(other)
  other.is_a?(Mixin) && names == other.names
end