Class: RBI::Const

Inherits:
NodeWithComments show all
Extended by:
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

Consts

Instance Attribute Summary collapse

Attributes inherited from NodeWithComments

#comments

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from NodeWithComments

#merge_with, #oneline?

Methods inherited from Node

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

Constructor Details

#initialize(name, value, loc: nil, comments: [], &block) ⇒ Const

Returns a new instance of Const.



307
308
309
310
311
312
# File 'lib/rbi/model.rb', line 307

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



296
297
298
# File 'lib/rbi/model.rb', line 296

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



296
297
298
# File 'lib/rbi/model.rb', line 296

def value
  @value
end

Instance Method Details

#accept_printer(v) ⇒ Object



289
290
291
292
293
294
295
296
# File 'lib/rbi/printer.rb', line 289

def accept_printer(v)
  previous_node = v.previous_node
  v.printn if previous_node && (!previous_node.oneline? || !oneline?)

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

#compatible_with?(other) ⇒ Boolean

Returns:

  • (Boolean)


373
374
375
# File 'lib/rbi/rewriters/merge_trees.rb', line 373

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

#fully_qualified_nameObject



315
316
317
318
# File 'lib/rbi/model.rb', line 315

def fully_qualified_name
  return name if name.start_with?("::")
  "#{parent_scope&.fully_qualified_name}::#{name}"
end

#index_idsObject



92
93
94
# File 'lib/rbi/index.rb', line 92

def index_ids
  [fully_qualified_name]
end

#to_sObject



321
322
323
# File 'lib/rbi/model.rb', line 321

def to_s
  fully_qualified_name
end