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



4862
4863
4864
# File 'lib/syntax_tree/node.rb', line 4862

def initialize(lbrace)
  @lbrace = lbrace
end

Instance Attribute Details

#lbraceObject (readonly)

LBrace

the opening brace



4860
4861
4862
# File 'lib/syntax_tree/node.rb', line 4860

def lbrace
  @lbrace
end

Instance Method Details

#format(q) ⇒ Object



4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
# File 'lib/syntax_tree/node.rb', line 4866

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