Class: SyntaxTree::Words
Overview
Words represents a string literal array with interpolation.
%W[one two three]
Instance Attribute Summary collapse
-
#beginning ⇒ Object
readonly
- WordsBeg
-
the token that opens this array literal.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#elements ⇒ Object
readonly
- Array[ Word ]
-
the elements of 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(beginning:, elements:, location:, comments: []) ⇒ Words
constructor
A new instance of Words.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(beginning:, elements:, location:, comments: []) ⇒ Words
Returns a new instance of Words.
9964 9965 9966 9967 9968 9969 |
# File 'lib/syntax_tree/node.rb', line 9964 def initialize(beginning:, elements:, location:, comments: []) @beginning = beginning @elements = elements @location = location @comments = comments end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- WordsBeg
-
the token that opens this array literal
9956 9957 9958 |
# File 'lib/syntax_tree/node.rb', line 9956 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9962 9963 9964 |
# File 'lib/syntax_tree/node.rb', line 9962 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ Word ]
-
the elements of this array
9959 9960 9961 |
# File 'lib/syntax_tree/node.rb', line 9959 def elements @elements end |
Instance Method Details
#accept(visitor) ⇒ Object
9971 9972 9973 |
# File 'lib/syntax_tree/node.rb', line 9971 def accept(visitor) visitor.visit_words(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9975 9976 9977 |
# File 'lib/syntax_tree/node.rb', line 9975 def child_nodes [] end |
#deconstruct_keys(_keys) ⇒ Object
9981 9982 9983 9984 9985 9986 9987 9988 |
# File 'lib/syntax_tree/node.rb', line 9981 def deconstruct_keys(_keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 |
# File 'lib/syntax_tree/node.rb', line 9990 def format(q) opening, closing = "%W[", "]" if elements.any? { |element| element.match?(/[\[\]]/) } opening = beginning.value closing = Quotes.matching(opening[2]) end q.group(0, opening, closing) do q.indent do q.breakable("") q.seplist(elements, -> { q.breakable }) do |element| q.format(element) end end q.breakable("") end end |