Class: SyntaxTree::ERB::Block
Overview
This is a base class for a block that contains:
-
an opening
-
optional elements
-
optional closing
Direct Known Subclasses
Instance Attribute Summary collapse
-
#closing ⇒ Object
readonly
Returns the value of attribute closing.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#opening ⇒ Object
readonly
Returns the value of attribute opening.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(opening:, location:, elements: nil, closing: nil) ⇒ Block
constructor
A new instance of Block.
- #new_line ⇒ Object
- #without_new_line ⇒ Object
Methods inherited from Node
#format, #pretty_print, #skip?
Constructor Details
#initialize(opening:, location:, elements: nil, closing: nil) ⇒ Block
Returns a new instance of Block.
146 147 148 149 150 151 |
# File 'lib/syntax_tree/erb/nodes.rb', line 146 def initialize(opening:, location:, elements: nil, closing: nil) @opening = opening @elements = elements || [] @closing = closing @location = location end |
Instance Attribute Details
#closing ⇒ Object (readonly)
Returns the value of attribute closing.
145 146 147 |
# File 'lib/syntax_tree/erb/nodes.rb', line 145 def closing @closing end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
145 146 147 |
# File 'lib/syntax_tree/erb/nodes.rb', line 145 def elements @elements end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
145 146 147 |
# File 'lib/syntax_tree/erb/nodes.rb', line 145 def location @location end |
#opening ⇒ Object (readonly)
Returns the value of attribute opening.
145 146 147 |
# File 'lib/syntax_tree/erb/nodes.rb', line 145 def opening @opening end |
Instance Method Details
#accept(visitor) ⇒ Object
153 154 155 |
# File 'lib/syntax_tree/erb/nodes.rb', line 153 def accept(visitor) visitor.visit_block(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
157 158 159 |
# File 'lib/syntax_tree/erb/nodes.rb', line 157 def child_nodes [opening, *elements, closing].compact end |
#deconstruct_keys(keys) ⇒ Object
173 174 175 176 177 178 179 180 |
# File 'lib/syntax_tree/erb/nodes.rb', line 173 def deconstruct_keys(keys) { opening: opening, elements: elements, closing: closing, location: location } end |
#new_line ⇒ Object
161 162 163 |
# File 'lib/syntax_tree/erb/nodes.rb', line 161 def new_line closing.new_line if closing.respond_to?(:new_line) end |
#without_new_line ⇒ Object
165 166 167 168 169 |
# File 'lib/syntax_tree/erb/nodes.rb', line 165 def without_new_line self.class.new( **deconstruct_keys([]).merge(closing: closing&.without_new_line) ) end |