Class: Tapioca::RBI::TStructField

Inherits:
Node
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/tapioca/rbi/model.rb,
lib/tapioca/rbi/printer.rb

Direct Known Subclasses

TStructConst, TStructProp

Instance Attribute Summary collapse

Attributes inherited from Node

#parent_tree

Instance Method Summary collapse

Methods inherited from Node

#detach, #group_kind, #oneline?, #print, #string

Constructor Details

#initialize(name, type, default: nil) ⇒ TStructField

Returns a new instance of TStructField.



334
335
336
337
338
339
# File 'lib/tapioca/rbi/model.rb', line 334

def initialize(name, type, default: nil)
  super()
  @name = name
  @type = type
  @default = default
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



325
326
327
# File 'lib/tapioca/rbi/model.rb', line 325

def default
  @default
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#accept_printer(v) ⇒ Object



333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/tapioca/rbi/printer.rb', line 333

def accept_printer(v)
  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