Represents the use of the if keyword, either in the block form or the modifier form, or a ternary expression.

bar if foo
^^^^^^^^^^

if foo then bar end
^^^^^^^^^^^^^^^^^^^

foo ? bar : baz
^^^^^^^^^^^^^^^
Attributes
Read

The node for the condition the IfNode is testing.

if foo
   ^^^
  bar
end

bar if foo
       ^^^

foo ? bar : baz
^^^
Read

Represents the body of statements that will be executed when the predicate is evaluated as truthy. Will be nil when no body is provided.

if foo
  bar
  ^^^
  baz
  ^^^
end
Read

Represents an ElseNode or an IfNode when there is an else or an elsif in the if statement.

if foo
  bar
elsif baz
^^^^^^^^^
  qux
  ^^^
end
^^^

if foo then bar else baz end
                ^^^^^^^^^^^^
Class Methods

Initialize a new IfNode node.

Return a symbol representation of this node type. See Node::type.

Instance Methods

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.

def accept: (Visitor visitor) -> void

def child_nodes: () -> Array

def comment_targets: () -> Array[Node | Location]

Returns the subsequent if/elsif/else clause of the if node. This method is deprecated in favor of subsequent.

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?if_keyword_loc: Location?, ?predicate: Prism::node, ?then_keyword_loc: Location?, ?statements: StatementsNode?, ?subsequent: ElseNode | IfNode | nil, ?end_keyword_loc: Location?) -> IfNode

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, if_keyword_loc: Location?, predicate: Prism::node, then_keyword_loc: Location?, statements: StatementsNode?, subsequent: ElseNode | IfNode | nil, end_keyword_loc: Location? }

def end_keyword: () -> String?

The location of the end keyword if present, nil otherwise.

if foo
  bar
end
^^^

def if_keyword: () -> String?

The location of the if keyword if present.

bar if foo
    ^^

The if_keyword_loc field will be nil when the IfNode represents a ternary expression.

def inspect -> String

Save the end_keyword_loc location using the given saved source so that it can be retrieved later.

Save the if_keyword_loc location using the given saved source so that it can be retrieved later.

Save the then_keyword_loc location using the given saved source so that it can be retrieved later.

def then_keyword: () -> String?

The location of the then keyword (if present) or the ? in a ternary expression, nil otherwise.

if foo then bar end
       ^^^^

a ? b : c
  ^

Return a symbol representation of this node type. See Node#type.