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
11180 11181 11182 11183 11184 11185 11186 |
# File 'lib/syntax_tree/node.rb', line 11180 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
11178 11179 11180 |
# File 'lib/syntax_tree/node.rb', line 11178 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil | Elsif | Else
-
the next clause in the chain
11175 11176 11177 |
# File 'lib/syntax_tree/node.rb', line 11175 def consequent @consequent end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
11169 11170 11171 |
# File 'lib/syntax_tree/node.rb', line 11169 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
11172 11173 11174 |
# File 'lib/syntax_tree/node.rb', line 11172 def statements @statements end |
Instance Method Details
#===(other) ⇒ Object
11225 11226 11227 11228 |
# File 'lib/syntax_tree/node.rb', line 11225 def ===(other) other.is_a?(UnlessNode) && predicate === other.predicate && statements === other.statements && consequent === other.consequent end |
#accept(visitor) ⇒ Object
11188 11189 11190 |
# File 'lib/syntax_tree/node.rb', line 11188 def accept(visitor) visitor.visit_unless(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11192 11193 11194 |
# File 'lib/syntax_tree/node.rb', line 11192 def child_nodes [predicate, statements, consequent] end |
#copy(predicate: nil, statements: nil, consequent: nil, location: nil) ⇒ Object
11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 |
# File 'lib/syntax_tree/node.rb', line 11196 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
11211 11212 11213 11214 11215 11216 11217 11218 11219 |
# File 'lib/syntax_tree/node.rb', line 11211 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
11221 11222 11223 |
# File 'lib/syntax_tree/node.rb', line 11221 def format(q) ConditionalFormatter.new("unless", self).format(q) end |
#modifier? ⇒ Boolean
Checks if the node was originally found in the modifier form.
11231 11232 11233 |
# File 'lib/syntax_tree/node.rb', line 11231 def modifier? predicate.location.start_char > statements.location.start_char end |