Class: RBI::Helper

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

Overview

Sorbet’s misc.

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, loc: nil, comments: [], &block) ⇒ Helper

Returns a new instance of Helper.



1296
1297
1298
1299
1300
# File 'lib/rbi/model.rb', line 1296

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



1286
1287
1288
# File 'lib/rbi/model.rb', line 1286

def name
  @name
end

Instance Method Details

#accept_printer(v) ⇒ Object



757
758
759
760
761
762
763
# File 'lib/rbi/printer.rb', line 757

def accept_printer(v)
  print_blank_line_before(v)

  v.printl("# #{loc}") if loc && v.print_locs
  v.visit_all(comments)
  v.printl("#{name}!")
end

#compatible_with?(other) ⇒ Boolean

Returns:

  • (Boolean)


510
511
512
# File 'lib/rbi/rewriters/merge_trees.rb', line 510

def compatible_with?(other)
  other.is_a?(Helper) && name == other.name
end

#index_idsObject



159
160
161
# File 'lib/rbi/index.rb', line 159

def index_ids
  [to_s]
end

#to_sObject



1303
1304
1305
# File 'lib/rbi/model.rb', line 1303

def to_s
  "#{parent_scope&.fully_qualified_name}.#{name}!"
end