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

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

Returns a new instance of TStructField.



1166
1167
1168
1169
1170
1171
# File 'lib/rbi/model.rb', line 1166

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.



1155
1156
1157
# File 'lib/rbi/model.rb', line 1155

def default
  @default
end

#nameObject

Returns the value of attribute name.



1152
1153
1154
# File 'lib/rbi/model.rb', line 1152

def name
  @name
end

#typeObject

Returns the value of attribute type.



1152
1153
1154
# File 'lib/rbi/model.rb', line 1152

def type
  @type
end

Instance Method Details

#accept_printer(v) ⇒ Object



773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
# File 'lib/rbi/printer.rb', line 773

def accept_printer(v)
  print_blank_line_before(v)

  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)


538
539
540
# File 'lib/rbi/rewriters/merge_trees.rb', line 538

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

#fully_qualified_namesObject



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

def fully_qualified_names; end