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.



1064
1065
1066
# File 'lib/syntax_tree/node.rb', line 1064

def initialize(contents)
  @contents = contents
end

Instance Attribute Details

#contentsObject (readonly)

Args

the contents of the array



1062
1063
1064
# File 'lib/syntax_tree/node.rb', line 1062

def contents
  @contents
end

Instance Method Details

#format(q) ⇒ Object



1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
# File 'lib/syntax_tree/node.rb', line 1068

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