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.



5637
5638
5639
# File 'lib/syntax_tree/node.rb', line 5637

def initialize(lbrace)
  @lbrace = lbrace
end

Instance Attribute Details

#lbraceObject (readonly)

LBrace

the opening brace



5635
5636
5637
# File 'lib/syntax_tree/node.rb', line 5635

def lbrace
  @lbrace
end

Instance Method Details

#format(q) ⇒ Object



5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
# File 'lib/syntax_tree/node.rb', line 5641

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