Class: RBI::TStructField

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

Direct Known Subclasses

TStructConst, TStructProp

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, type, default: nil, loc: nil, comments: []) ⇒ TStructField

Returns a new instance of TStructField.



738
739
740
741
742
743
# File 'lib/rbi/model.rb', line 738

def initialize(name, type, default: nil, loc: nil, comments: [])
  super(loc: loc, comments: comments)
  @name = name
  @type = type
  @default = default
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



727
728
729
# File 'lib/rbi/model.rb', line 727

def default
  @default
end

#nameObject

Returns the value of attribute name.



724
725
726
# File 'lib/rbi/model.rb', line 724

def name
  @name
end

#typeObject

Returns the value of attribute type.



724
725
726
# File 'lib/rbi/model.rb', line 724

def type
  @type
end

Instance Method Details

#accept_printer(v) ⇒ Object



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/rbi/printer.rb', line 553

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)
  case self
  when TStructProp
    v.printt("prop")
  when TStructConst
    v.printt("const")
  end
  v.print(" :#{name}, #{type}")
  default = self.default
  v.print(", default: #{default}") if default
  v.printn
end

#compatible_with?(other) ⇒ Boolean

Returns:

  • (Boolean)


455
456
457
# File 'lib/rbi/rewriters/merge_trees.rb', line 455

def compatible_with?(other)
  other.is_a?(TStructField) && name == other.name && type == other.type && default == other.default
end

#fully_qualified_namesObject



746
# File 'lib/rbi/model.rb', line 746

def fully_qualified_names; end