Class: SyntaxTree::ArrayLiteral
Overview
ArrayLiteral represents an array literal, which can optionally contain elements.
[]
[one, two, three]
Defined Under Namespace
Classes: BreakableSpaceSeparator, EmptyWithCommentsFormatter, QSymbolsFormatter, QWordsFormatter, VarRefsFormatter
Constant Summary collapse
- BREAKABLE_SPACE_SEPARATOR =
BreakableSpaceSeparator.new
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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(lbracket:, contents:, location:, comments: []) ⇒ ArrayLiteral
958 959 960 961 962 963 |
# File 'lib/syntax_tree/node.rb', line 958 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
956 957 958 |
# File 'lib/syntax_tree/node.rb', line 956 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | Args
-
the contents of the array
953 954 955 |
# File 'lib/syntax_tree/node.rb', line 953 def contents @contents end |
#lbracket ⇒ Object (readonly)
- LBracket
-
the bracket that opens this array
950 951 952 |
# File 'lib/syntax_tree/node.rb', line 950 def lbracket @lbracket end |
Instance Method Details
#accept(visitor) ⇒ Object
965 966 967 |
# File 'lib/syntax_tree/node.rb', line 965 def accept(visitor) visitor.visit_array(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
969 970 971 |
# File 'lib/syntax_tree/node.rb', line 969 def child_nodes [lbracket, contents] end |
#deconstruct_keys(_keys) ⇒ Object
975 976 977 978 979 980 981 982 |
# File 'lib/syntax_tree/node.rb', line 975 def deconstruct_keys(_keys) { lbracket: lbracket, contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 |
# File 'lib/syntax_tree/node.rb', line 984 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_empty q.format(contents) q.if_break { q.text(",") } if q.trailing_comma? end end q.breakable_empty q.text("]") end end |