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.



4743
4744
4745
# File 'lib/syntax_tree/node.rb', line 4743

def initialize(lbrace)
  @lbrace = lbrace
end

Instance Attribute Details

#lbraceObject (readonly)

LBrace

the opening brace



4741
4742
4743
# File 'lib/syntax_tree/node.rb', line 4741

def lbrace
  @lbrace
end

Instance Method Details

#format(q) ⇒ Object



4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
# File 'lib/syntax_tree/node.rb', line 4747

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