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: []) ⇒ TEnumBlock

Returns a new instance of TEnumBlock.



805
806
807
808
# File 'lib/rbi/model.rb', line 805

def initialize(names = [], loc: nil, comments: [])
  super(loc: loc, comments: comments)
  @names = names
end

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



802
803
804
# File 'lib/rbi/model.rb', line 802

def names
  @names
end

Instance Method Details

#<<(name) ⇒ Object



816
817
818
# File 'lib/rbi/model.rb', line 816

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

#accept_printer(v) ⇒ Object



576
577
578
579
580
581
582
583
584
585
586
# File 'lib/rbi/printer.rb', line 576

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)


811
812
813
# File 'lib/rbi/model.rb', line 811

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



473
474
475
476
477
478
479
# File 'lib/rbi/rewriters/merge_trees.rb', line 473

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



821
822
823
# File 'lib/rbi/model.rb', line 821

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