class YARP::WhenNode
Represents the use of the ‘when` keyword within a case statement.
case true when true ^^^^^^^^^ end
Attributes
conditions[R]
attr_reader conditions: Array
keyword_loc[R]
attr_reader keyword_loc
: Location
statements[R]
attr_reader statements: StatementsNode
?
Public Class Methods
new(keyword_loc, conditions, statements, location)
click to toggle source
def initialize: (keyword_loc
: Location
, conditions: Array, statements: StatementsNode
?, location: Location
) -> void
# File lib/yarp/node.rb, line 11541 def initialize(keyword_loc, conditions, statements, location) @keyword_loc = keyword_loc @conditions = conditions @statements = statements @location = location end
Public Instance Methods
accept(visitor)
click to toggle source
def accept: (visitor: Visitor
) -> void
# File lib/yarp/node.rb, line 11549 def accept(visitor) visitor.visit_when_node(self) end
child_nodes()
click to toggle source
def child_nodes
: () -> Array[nil | Node]
# File lib/yarp/node.rb, line 11554 def child_nodes [*conditions, statements] end
Also aliased as: deconstruct
comment_targets()
click to toggle source
def comment_targets
: () -> Array[Node | Location]
# File lib/yarp/node.rb, line 11567 def comment_targets [keyword_loc, *conditions, *statements] end
compact_child_nodes()
click to toggle source
def compact_child_nodes
: () -> Array
# File lib/yarp/node.rb, line 11559 def compact_child_nodes compact = [] compact.concat(conditions) compact << statements if statements compact end
copy(**params)
click to toggle source
def copy: (**params) -> WhenNode
# File lib/yarp/node.rb, line 11572 def copy(**params) WhenNode.new( params.fetch(:keyword_loc) { keyword_loc }, params.fetch(:conditions) { conditions }, params.fetch(:statements) { statements }, params.fetch(:location) { location }, ) end
deconstruct_keys(keys)
click to toggle source
inspect(inspector = NodeInspector.new)
click to toggle source
# File lib/yarp/node.rb, line 11594 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" inspector << "├── conditions: #{inspector.list("#{inspector.prefix}│ ", conditions)}" if (statements = self.statements).nil? inspector << "└── statements: ∅\n" else inspector << "└── statements:\n" inspector << statements.inspect(inspector.child_inspector(" ")).delete_prefix(inspector.prefix) end inspector.to_str end
keyword()
click to toggle source
def keyword: () -> String
# File lib/yarp/node.rb, line 11590 def keyword keyword_loc.slice end