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.
903 904 905 906 907 908 |
# File 'lib/syntax_tree/node.rb', line 903 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
901 902 903 |
# File 'lib/syntax_tree/node.rb', line 901 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | Args
-
the contents of the array
898 899 900 |
# File 'lib/syntax_tree/node.rb', line 898 def contents @contents end |
#lbracket ⇒ Object (readonly)
- LBracket
-
the bracket that opens this array
895 896 897 |
# File 'lib/syntax_tree/node.rb', line 895 def lbracket @lbracket end |
Instance Method Details
#accept(visitor) ⇒ Object
910 911 912 |
# File 'lib/syntax_tree/node.rb', line 910 def accept(visitor) visitor.visit_array(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
914 915 916 |
# File 'lib/syntax_tree/node.rb', line 914 def child_nodes [lbracket, contents] end |
#deconstruct_keys(_keys) ⇒ Object
920 921 922 923 924 925 926 927 |
# File 'lib/syntax_tree/node.rb', line 920 def deconstruct_keys(_keys) { lbracket: lbracket, contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 |
# File 'lib/syntax_tree/node.rb', line 929 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 |