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.
104 105 106 107 108 109 |
# File 'lib/syntax_tree/erb/nodes.rb', line 104 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.
103 104 105 |
# File 'lib/syntax_tree/erb/nodes.rb', line 103 def closing @closing end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
103 104 105 |
# File 'lib/syntax_tree/erb/nodes.rb', line 103 def elements @elements end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
103 104 105 |
# File 'lib/syntax_tree/erb/nodes.rb', line 103 def location @location end |
#opening ⇒ Object (readonly)
Returns the value of attribute opening.
103 104 105 |
# File 'lib/syntax_tree/erb/nodes.rb', line 103 def opening @opening end |
Instance Method Details
#accept(visitor) ⇒ Object
111 112 113 |
# File 'lib/syntax_tree/erb/nodes.rb', line 111 def accept(visitor) visitor.visit_block(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
115 116 117 |
# File 'lib/syntax_tree/erb/nodes.rb', line 115 def child_nodes [opening, *elements, closing].compact end |
#deconstruct_keys(keys) ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/syntax_tree/erb/nodes.rb', line 131 def deconstruct_keys(keys) { opening: opening, elements: elements, closing: closing, location: location } end |
#new_line ⇒ Object
119 120 121 |
# File 'lib/syntax_tree/erb/nodes.rb', line 119 def new_line closing.new_line if closing.respond_to?(:new_line) end |
#without_new_line ⇒ Object
123 124 125 126 127 |
# File 'lib/syntax_tree/erb/nodes.rb', line 123 def without_new_line self.class.new( **deconstruct_keys([]).merge(closing: closing&.without_new_line) ) end |