Class: RBI::TEnumBlock

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

Instance Attribute Summary collapse

Attributes inherited from NodeWithComments

#comments

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from NodeWithComments

#oneline?

Methods inherited from Node

#compatible_with?, #detach, #group_kind, #oneline?, #parent_conflict_tree, #parent_scope, #print, #replace, #string

Constructor Details

#initialize(names = [], loc: nil, comments: [], &block) ⇒ TEnumBlock

Returns a new instance of TEnumBlock.



1145
1146
1147
1148
1149
# File 'lib/rbi/model.rb', line 1145

def initialize(names = [], loc: nil, comments: [], &block)
  super(loc: loc, comments: comments)
  @names = names
  block&.call(self)
end

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



1135
1136
1137
# File 'lib/rbi/model.rb', line 1135

def names
  @names
end

Instance Method Details

#<<(name) ⇒ Object



1157
1158
1159
# File 'lib/rbi/model.rb', line 1157

def <<(name)
  @names << name
end

#accept_printer(v) ⇒ Object



665
666
667
668
669
670
671
672
673
674
675
# File 'lib/rbi/printer.rb', line 665

def accept_printer(v)
  v.printl("# #{loc}") if loc && v.print_locs
  v.visit_all(comments)
  v.printl("enums do")
  v.indent
  names.each do |name|
    v.printl("#{name} = new")
  end
  v.dedent
  v.printl("end")
end

#empty?Boolean

Returns:

  • (Boolean)


1152
1153
1154
# File 'lib/rbi/model.rb', line 1152

def empty?
  names.empty?
end

#index_idsObject



182
183
184
# File 'lib/rbi/index.rb', line 182

def index_ids
  [to_s]
end

#merge_with(other) ⇒ Object



513
514
515
516
517
518
519
# File 'lib/rbi/rewriters/merge_trees.rb', line 513

def merge_with(other)
  return unless other.is_a?(TEnumBlock)
  super
  other.names.each do |name|
    names << name unless names.include?(name)
  end
end

#to_sObject



1162
1163
1164
# File 'lib/rbi/model.rb', line 1162

def to_s
  "#{parent_scope&.fully_qualified_name}.enums"
end