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
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(lbracket:, contents:, location:, comments: []) ⇒ ArrayLiteral
constructor
A new instance of ArrayLiteral.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(lbracket:, contents:, location:, comments: []) ⇒ ArrayLiteral
Returns a new instance of ArrayLiteral.
998 999 1000 1001 1002 1003 |
# File 'lib/syntax_tree/node.rb', line 998 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
996 997 998 |
# File 'lib/syntax_tree/node.rb', line 996 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | Args
-
the contents of the array
993 994 995 |
# File 'lib/syntax_tree/node.rb', line 993 def contents @contents end |
#lbracket ⇒ Object (readonly)
- LBracket
-
the bracket that opens this array
990 991 992 |
# File 'lib/syntax_tree/node.rb', line 990 def lbracket @lbracket end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
1005 1006 1007 |
# File 'lib/syntax_tree/node.rb', line 1005 def child_nodes [lbracket, contents] end |
#deconstruct_keys(keys) ⇒ Object
1011 1012 1013 1014 1015 1016 1017 1018 |
# File 'lib/syntax_tree/node.rb', line 1011 def deconstruct_keys(keys) { lbracket: lbracket, contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 |
# File 'lib/syntax_tree/node.rb', line 1020 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 |
#pretty_print(q) ⇒ Object
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 |
# File 'lib/syntax_tree/node.rb', line 1051 def pretty_print(q) q.group(2, "(", ")") do q.text("array") q.breakable q.pp(contents) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
1062 1063 1064 1065 1066 |
# File 'lib/syntax_tree/node.rb', line 1062 def to_json(*opts) { type: :array, cnts: contents, loc: location, cmts: comments }.to_json( *opts ) end |