Class: SyntaxTree::ArrayLiteral
Overview
ArrayLiteral represents an array literal, which can optionally contain elements.
[]
[one, two, three]
Defined Under Namespace
Classes: QSymbolsFormatter, QWordsFormatter, VarRefsFormatter
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#contents ⇒ Object
readonly
- nil | Args
-
the contents of the array.
-
#lbracket ⇒ Object
readonly
- LBracket
-
the bracket that opens this array.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(lbracket:, contents:, location:, comments: []) ⇒ ArrayLiteral
constructor
A new instance of ArrayLiteral.
Methods inherited from Node
Constructor Details
#initialize(lbracket:, contents:, location:, comments: []) ⇒ ArrayLiteral
Returns a new instance of ArrayLiteral.
813 814 815 816 817 818 |
# File 'lib/syntax_tree/node.rb', line 813 def initialize(lbracket:, contents:, location:, comments: []) @lbracket = lbracket @contents = contents @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
811 812 813 |
# File 'lib/syntax_tree/node.rb', line 811 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | Args
-
the contents of the array
808 809 810 |
# File 'lib/syntax_tree/node.rb', line 808 def contents @contents end |
#lbracket ⇒ Object (readonly)
- LBracket
-
the bracket that opens this array
805 806 807 |
# File 'lib/syntax_tree/node.rb', line 805 def lbracket @lbracket end |
Instance Method Details
#accept(visitor) ⇒ Object
820 821 822 |
# File 'lib/syntax_tree/node.rb', line 820 def accept(visitor) visitor.visit_array(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
824 825 826 |
# File 'lib/syntax_tree/node.rb', line 824 def child_nodes [lbracket, contents] end |
#deconstruct_keys(keys) ⇒ Object
830 831 832 833 834 835 836 837 |
# File 'lib/syntax_tree/node.rb', line 830 def deconstruct_keys(keys) { lbracket: lbracket, contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 |
# File 'lib/syntax_tree/node.rb', line 839 def format(q) if qwords? QWordsFormatter.new(contents).format(q) return end if qsymbols? QSymbolsFormatter.new(contents).format(q) return end if var_refs?(q) VarRefsFormatter.new(contents).format(q) return end q.group do q.format(lbracket) if contents q.indent do q.breakable("") q.format(contents) end end q.breakable("") q.text("]") end end |