class YARP::CaseNode

Represents the use of a case statement.

case true ^^^^^^^^^ when false end

Attributes

case_keyword_loc[R]

attr_reader case_keyword_loc: Location

conditions[R]

attr_reader conditions: Array

consequent[R]

attr_reader consequent: ElseNode?

end_keyword_loc[R]

attr_reader end_keyword_loc: Location

predicate[R]

attr_reader predicate: Node?

Public Class Methods

new(predicate, conditions, consequent, case_keyword_loc, end_keyword_loc, location) click to toggle source

def initialize: (predicate: Node?, conditions: Array, consequent: ElseNode?, case_keyword_loc: Location, end_keyword_loc: Location, location: Location) -> void

# File yarp/node.rb, line 2017
def initialize(predicate, conditions, consequent, case_keyword_loc, end_keyword_loc, location)
  @predicate = predicate
  @conditions = conditions
  @consequent = consequent
  @case_keyword_loc = case_keyword_loc
  @end_keyword_loc = end_keyword_loc
  @location = location
end

Public Instance Methods

accept(visitor) click to toggle source

def accept: (visitor: Visitor) -> void

# File yarp/node.rb, line 2027
def accept(visitor)
  visitor.visit_case_node(self)
end
case_keyword() click to toggle source

def case_keyword: () -> String

# File yarp/node.rb, line 2062
def case_keyword
  case_keyword_loc.slice
end
child_nodes() click to toggle source

def child_nodes: () -> Array[nil | Node]

# File yarp/node.rb, line 2032
def child_nodes
  [predicate, *conditions, consequent]
end
Also aliased as: deconstruct
comment_targets() click to toggle source

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

# File yarp/node.rb, line 2037
def comment_targets
  [*predicate, *conditions, *consequent, case_keyword_loc, end_keyword_loc]
end
copy(**params) click to toggle source

def copy: (**params) -> CaseNode

# File yarp/node.rb, line 2042
def copy(**params)
  CaseNode.new(
    params.fetch(:predicate) { predicate },
    params.fetch(:conditions) { conditions },
    params.fetch(:consequent) { consequent },
    params.fetch(:case_keyword_loc) { case_keyword_loc },
    params.fetch(:end_keyword_loc) { end_keyword_loc },
    params.fetch(:location) { location },
  )
end
deconstruct()

def deconstruct: () -> Array[nil | Node]

Alias for: child_nodes
deconstruct_keys(keys) click to toggle source

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]

# File yarp/node.rb, line 2057
def deconstruct_keys(keys)
  { predicate: predicate, conditions: conditions, consequent: consequent, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc, location: location }
end
end_keyword() click to toggle source

def end_keyword: () -> String

# File yarp/node.rb, line 2067
def end_keyword
  end_keyword_loc.slice
end
inspect(inspector = NodeInspector.new) click to toggle source
# File yarp/node.rb, line 2071
def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  if (predicate = self.predicate).nil?
    inspector << "├── predicate: ∅\n"
  else
    inspector << "├── predicate:\n"
    inspector << predicate.inspect(inspector.child_inspector("│   ")).delete_prefix(inspector.prefix)
  end
  inspector << "├── conditions: #{inspector.list("#{inspector.prefix}│   ", conditions)}"
  if (consequent = self.consequent).nil?
    inspector << "├── consequent: ∅\n"
  else
    inspector << "├── consequent:\n"
    inspector << consequent.inspect(inspector.child_inspector("│   ")).delete_prefix(inspector.prefix)
  end
  inspector << "├── case_keyword_loc: #{inspector.location(case_keyword_loc)}\n"
  inspector << "└── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n"
  inspector.to_str
end