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.



5659
5660
5661
# File 'lib/syntax_tree/node.rb', line 5659

def initialize(lbrace)
  @lbrace = lbrace
end

Instance Attribute Details

#lbraceObject (readonly)

LBrace

the opening brace



5657
5658
5659
# File 'lib/syntax_tree/node.rb', line 5657

def lbrace
  @lbrace
end

Instance Method Details

#format(q) ⇒ Object



5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
# File 'lib/syntax_tree/node.rb', line 5663

def format(q)
  q.group do
    q.text("{")
    q.indent do
      lbrace.comments.each do |comment|
        q.breakable_force
        comment.format(q)
      end
    end
    q.breakable_force
    q.text("}")
  end
end