Class: SyntaxTree::ArrayLiteral
Overview
ArrayLiteral represents an array literal, which can optionally contain elements.
[]
[one, two, three]
Defined Under Namespace
Classes: EmptyWithCommentsFormatter, 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.
851 852 853 854 855 856 |
# File 'lib/syntax_tree/node.rb', line 851 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
849 850 851 |
# File 'lib/syntax_tree/node.rb', line 849 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | Args
-
the contents of the array
846 847 848 |
# File 'lib/syntax_tree/node.rb', line 846 def contents @contents end |
#lbracket ⇒ Object (readonly)
- LBracket
-
the bracket that opens this array
843 844 845 |
# File 'lib/syntax_tree/node.rb', line 843 def lbracket @lbracket end |
Instance Method Details
#accept(visitor) ⇒ Object
858 859 860 |
# File 'lib/syntax_tree/node.rb', line 858 def accept(visitor) visitor.visit_array(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
862 863 864 |
# File 'lib/syntax_tree/node.rb', line 862 def child_nodes [lbracket, contents] end |
#deconstruct_keys(keys) ⇒ Object
868 869 870 871 872 873 874 875 |
# File 'lib/syntax_tree/node.rb', line 868 def deconstruct_keys(keys) { lbracket: lbracket, contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 |
# File 'lib/syntax_tree/node.rb', line 877 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 if empty_with_comments? EmptyWithCommentsFormatter.new(lbracket).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 |