Class: SyntaxTree::HashLiteral::EmptyWithCommentsFormatter

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

Overview

This is a special formatter used if the hash 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(lbrace) ⇒ EmptyWithCommentsFormatter

Returns a new instance of EmptyWithCommentsFormatter.



4671
4672
4673
# File 'lib/syntax_tree/node.rb', line 4671

def initialize(lbrace)
  @lbrace = lbrace
end

Instance Attribute Details

#lbraceObject (readonly)

LBrace

the opening brace



4669
4670
4671
# File 'lib/syntax_tree/node.rb', line 4669

def lbrace
  @lbrace
end

Instance Method Details

#format(q) ⇒ Object



4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
# File 'lib/syntax_tree/node.rb', line 4675

def format(q)
  q.group do
    q.text("{")
    q.indent do
      lbrace.comments.each do |comment|
        q.breakable(force: true)
        comment.format(q)
      end
    end
    q.breakable(force: true)
    q.text("}")
  end
end