Class: SyntaxTree::ArrayLiteral::QSymbolsFormatter

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

Overview

Formats an array of multiple simple symbol literals into the %i syntax.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ QSymbolsFormatter

Returns a new instance of QSymbolsFormatter.



1098
1099
1100
# File 'lib/syntax_tree/node.rb', line 1098

def initialize(contents)
  @contents = contents
end

Instance Attribute Details

#contentsObject (readonly)

Args

the contents of the array



1096
1097
1098
# File 'lib/syntax_tree/node.rb', line 1096

def contents
  @contents
end

Instance Method Details

#format(q) ⇒ Object



1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
# File 'lib/syntax_tree/node.rb', line 1102

def format(q)
  q.text("%i[")
  q.group do
    q.indent do
      q.breakable_empty
      q.seplist(contents.parts, BREAKABLE_SPACE_SEPARATOR) do |part|
        q.format(part.value)
      end
    end
    q.breakable_empty
  end
  q.text("]")
end