Class: SyntaxTree::ArrayLiteral::EmptyWithCommentsFormatter

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

Overview

This is a special formatter used if the array literal contains no values but does contain comments. In this case we do some special formatting to make sure the comments gets indented properly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lbracket) ⇒ EmptyWithCommentsFormatter

Returns a new instance of EmptyWithCommentsFormatter.



1123
1124
1125
# File 'lib/syntax_tree/node.rb', line 1123

def initialize(lbracket)
  @lbracket = lbracket
end

Instance Attribute Details

#lbracketObject (readonly)

LBracket

the opening bracket



1121
1122
1123
# File 'lib/syntax_tree/node.rb', line 1121

def lbracket
  @lbracket
end

Instance Method Details

#format(q) ⇒ Object



1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
# File 'lib/syntax_tree/node.rb', line 1127

def format(q)
  q.group do
    q.text("[")
    q.indent do
      lbracket.comments.each do |comment|
        q.breakable_force
        comment.format(q)
      end
    end
    q.breakable_force
    q.text("]")
  end
end