Class: Tapioca::RBI::Method

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

Overview

Methods and args

Instance Attribute Summary collapse

Attributes inherited from Node

#parent_tree

Instance Method Summary collapse

Methods inherited from Node

#detach, #group_kind, #print, #string

Constructor Details

#initialize(name, params: [], is_singleton: false, visibility: Visibility::Public, sigs: []) ⇒ Method

Returns a new instance of Method.



145
146
147
148
149
150
151
152
# File 'lib/tapioca/rbi/model.rb', line 145

def initialize(name, params: [], is_singleton: false, visibility: Visibility::Public, sigs: [])
  super()
  @name = name
  @params = params
  @is_singleton = is_singleton
  @visibility = visibility
  @sigs = sigs
end

Instance Attribute Details

#is_singletonObject

Returns the value of attribute is_singleton.



128
129
130
# File 'lib/tapioca/rbi/model.rb', line 128

def is_singleton
  @is_singleton
end

#nameObject

Returns the value of attribute name.



122
123
124
# File 'lib/tapioca/rbi/model.rb', line 122

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



125
126
127
# File 'lib/tapioca/rbi/model.rb', line 125

def params
  @params
end

#sigsObject

Returns the value of attribute sigs.



134
135
136
# File 'lib/tapioca/rbi/model.rb', line 134

def sigs
  @sigs
end

#visibilityObject

Returns the value of attribute visibility.



131
132
133
# File 'lib/tapioca/rbi/model.rb', line 131

def visibility
  @visibility
end

Instance Method Details

#<<(param) ⇒ Object



155
156
157
# File 'lib/tapioca/rbi/model.rb', line 155

def <<(param)
  @params << param
end

#accept_printer(v) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/tapioca/rbi/printer.rb', line 166

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

  v.visit_all(sigs)
  v.printt
  unless v.in_visibility_group || visibility == Visibility::Public
    v.print(visibility.visibility.to_s)
    v.print(" ")
  end
  v.print("def ")
  v.print("self.") if is_singleton
  v.print(name)
  unless params.empty?
    v.print("(")
    params.each_with_index do |param, index|
      v.print(", ") if index > 0
      v.visit(param)
    end
    v.print(")")
  end
  v.print("; end")
  v.printn
end

#oneline?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/tapioca/rbi/printer.rb', line 192

def oneline?
  sigs.empty?
end