Class: SyntaxTree::RBS::Members

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/rbs/utils.rb

Overview

Nodes which have members will all flow their printing through this class, which keeps track of

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Members

Returns a new instance of Members.



206
207
208
# File 'lib/syntax_tree/rbs/utils.rb', line 206

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



204
205
206
# File 'lib/syntax_tree/rbs/utils.rb', line 204

def node
  @node
end

Instance Method Details

#format(q) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/syntax_tree/rbs/utils.rb', line 210

def format(q)
  last_line = nil

  node.members.each do |member|
    q.breakable(force: true)

    if last_line && (member.location.start_line - last_line >= 2)
      q.breakable(force: true)
    end

    member.format(q)
    last_line = member.location.end_line
  end
end