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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(lbracket:, contents:, location:, comments: []) ⇒ ArrayLiteral
Returns a new instance of ArrayLiteral.
924 925 926 927 928 929 |
# File 'lib/syntax_tree/node.rb', line 924 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
922 923 924 |
# File 'lib/syntax_tree/node.rb', line 922 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | Args
-
the contents of the array
919 920 921 |
# File 'lib/syntax_tree/node.rb', line 919 def contents @contents end |
#lbracket ⇒ Object (readonly)
- LBracket
-
the bracket that opens this array
916 917 918 |
# File 'lib/syntax_tree/node.rb', line 916 def lbracket @lbracket end |
Instance Method Details
#accept(visitor) ⇒ Object
931 932 933 |
# File 'lib/syntax_tree/node.rb', line 931 def accept(visitor) visitor.visit_array(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
935 936 937 |
# File 'lib/syntax_tree/node.rb', line 935 def child_nodes [lbracket, contents] end |
#deconstruct_keys(_keys) ⇒ Object
941 942 943 944 945 946 947 948 |
# File 'lib/syntax_tree/node.rb', line 941 def deconstruct_keys(_keys) { lbracket: lbracket, contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 |
# File 'lib/syntax_tree/node.rb', line 950 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) q.if_break { q.text(",") } if q.trailing_comma? end end q.breakable("") q.text("]") end end |