class SyntaxTree::IfNode
If represents the first clause in an if
chain.
if predicate end
Attributes
Node
-
the expression to be checked
Statements
-
the expressions to be executed
Public Class Methods
Source
# File lib/syntax_tree/node.rb, line 6499 def initialize(predicate:, statements:, consequent:, location:) @predicate = predicate @statements = statements @consequent = consequent @location = location @comments = [] end
Public Instance Methods
Source
# File lib/syntax_tree/node.rb, line 6544 def ===(other) other.is_a?(IfNode) && predicate === other.predicate && statements === other.statements && consequent === other.consequent end
Source
# File lib/syntax_tree/node.rb, line 6507 def accept(visitor) visitor.visit_if(self) end
Source
# File lib/syntax_tree/node.rb, line 6511 def child_nodes [predicate, statements, consequent] end
Also aliased as: deconstruct
Source
# File lib/syntax_tree/node.rb, line 6515 def copy(predicate: nil, statements: nil, consequent: nil, location: nil) node = IfNode.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
Source
# File lib/syntax_tree/node.rb, line 6530 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, consequent: consequent, location: location, comments: comments } end
Source
# File lib/syntax_tree/node.rb, line 6540 def format(q) ConditionalFormatter.new("if", self).format(q) end
Source
# File lib/syntax_tree/node.rb, line 6550 def modifier? predicate.location.start_char > statements.location.start_char end
Checks if the node was originally found in the modifier form.