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.



1041
1042
1043
1044
1045
1046
# File 'lib/rbi/model.rb', line 1041

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.



1030
1031
1032
# File 'lib/rbi/model.rb', line 1030

def default
  @default
end

#nameObject

Returns the value of attribute name.



1027
1028
1029
# File 'lib/rbi/model.rb', line 1027

def name
  @name
end

#typeObject

Returns the value of attribute type.



1027
1028
1029
# File 'lib/rbi/model.rb', line 1027

def type
  @type
end

Instance Method Details

#accept_printer(v) ⇒ Object



642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/rbi/printer.rb', line 642

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)


495
496
497
# File 'lib/rbi/rewriters/merge_trees.rb', line 495

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

#fully_qualified_namesObject



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

def fully_qualified_names; end