Class: SyntaxTree::UnlessNode
Overview
Unless represents the first clause in an unless chain.
unless predicate
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#consequent ⇒ Object
readonly
- nil | Elsif | Else
-
the next clause in the chain.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(predicate: nil, statements: nil, consequent: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(predicate:, statements:, consequent:, location:) ⇒ UnlessNode
constructor
A new instance of UnlessNode.
-
#modifier? ⇒ Boolean
Checks if the node was originally found in the modifier form.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(predicate:, statements:, consequent:, location:) ⇒ UnlessNode
Returns a new instance of UnlessNode.
11145 11146 11147 11148 11149 11150 11151 |
# File 'lib/syntax_tree/node.rb', line 11145 def initialize(predicate:, statements:, consequent:, location:) @predicate = predicate @statements = statements @consequent = consequent @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11143 11144 11145 |
# File 'lib/syntax_tree/node.rb', line 11143 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil | Elsif | Else
-
the next clause in the chain
11140 11141 11142 |
# File 'lib/syntax_tree/node.rb', line 11140 def consequent @consequent end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
11134 11135 11136 |
# File 'lib/syntax_tree/node.rb', line 11134 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
11137 11138 11139 |
# File 'lib/syntax_tree/node.rb', line 11137 def statements @statements end |
Instance Method Details
#===(other) ⇒ Object
11190 11191 11192 11193 |
# File 'lib/syntax_tree/node.rb', line 11190 def ===(other) other.is_a?(UnlessNode) && predicate === other.predicate && statements === other.statements && consequent === other.consequent end |
#accept(visitor) ⇒ Object
11153 11154 11155 |
# File 'lib/syntax_tree/node.rb', line 11153 def accept(visitor) visitor.visit_unless(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11157 11158 11159 |
# File 'lib/syntax_tree/node.rb', line 11157 def child_nodes [predicate, statements, consequent] end |
#copy(predicate: nil, statements: nil, consequent: nil, location: nil) ⇒ Object
11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 11171 11172 |
# File 'lib/syntax_tree/node.rb', line 11161 def copy(predicate: nil, statements: nil, consequent: nil, location: nil) node = UnlessNode.new( predicate: predicate || self.predicate, statements: statements || self.statements, consequent: consequent || self.consequent, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
11176 11177 11178 11179 11180 11181 11182 11183 11184 |
# File 'lib/syntax_tree/node.rb', line 11176 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
11186 11187 11188 |
# File 'lib/syntax_tree/node.rb', line 11186 def format(q) ConditionalFormatter.new("unless", self).format(q) end |
#modifier? ⇒ Boolean
Checks if the node was originally found in the modifier form.
11196 11197 11198 |
# File 'lib/syntax_tree/node.rb', line 11196 def modifier? predicate.location.start_char > statements.location.start_char end |