class Prism::WhenNode
Represents the use of the when keyword within a case statement.
case true when true ^^^^^^^^^ end
Represents the use of the when keyword within a case statement.
case true when true ^^^^^^^^^ end
Public Class Methods
(Source source, Integer node_id, Location location, Integer flags, Location when_keyword_loc, Array[Prism::node] conditions, Location? then_keyword_loc, StatementsNode? statements) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32747 def initialize(source, node_id, location, flags, when_keyword_loc, conditions, then_keyword_loc, statements) @source = source @node_id = node_id @location = location @flags = flags @when_keyword_loc = when_keyword_loc @conditions = conditions @then_keyword_loc = then_keyword_loc @statements = statements end
Initialize a new WhenNode node.
Initialize a new WhenNode node.
: (Source source, Integer node_id, Location location, Integer flags, Location when_keyword_loc, Array conditions, Location? then_keyword_loc, StatementsNode? statements) -> void
Public Instance Methods
(untyped other) → boolish
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/sig/generated/prism/node.rbs, line 20949
def ===: (untyped other) -> boolish
: (untyped other) -> boolish
() → Array[Prism::node]
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32883 def conditions @conditions end
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/sig/generated/prism/node.rbs, line 20869
def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/sig/generated/prism/node.rbs, line 20882
def inspect: () -> String
: () -> String
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/sig/generated/prism/node_ext.rbs, line 263
def keyword: () -> String
: () -> String
() → Location
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/sig/generated/prism/node_ext.rbs, line 266
def keyword_loc: () -> Location
: () -> Location
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32920 def statements @statements end
Returns the statements attribute.
:call-seq: statements -> StatementsNode | nil
Returns the statements attribute.
: () -> StatementsNode?
Locations
Public Instance Methods
() → Location?
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32894 def then_keyword_loc location = @then_keyword_loc case location when nil nil when Location location else @then_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
Returns the Location represented by then_keyword_loc.
:category: Locations :call-seq: then_keyword_loc -> Location | nil
Returns the Location represented by then_keyword_loc.
: () -> Location?
() → Location
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32862 def when_keyword_loc location = @when_keyword_loc return location if location.is_a?(Location) @when_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
Returns the Location represented by when_keyword_loc.
:category: Locations :call-seq: when_keyword_loc -> Location
Returns the Location represented by when_keyword_loc.
: () -> Location
Node Interface
These methods are present on all subclasses of Node. Read the node interface docs for more information.
Public Class Methods
Public Instance Methods
(_Visitor visitor) → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32772 def accept(visitor) visitor.visit_when_node(self) end
() → Array[node?]
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32779 def child_nodes [*conditions, statements] end
() → Array[node]
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32797 def compact_child_nodes compact = [] #: Array[Prism::node] compact.concat(conditions) if (statements = self.statements); compact << statements; end compact end
(?node_id: Integer, ?location: Location, ?flags: Integer, ?when_keyword_loc: Location, ?conditions: Array[Prism::node], ?then_keyword_loc: Location?, ?statements: StatementsNode?) → WhenNode
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32810 def copy(node_id: self.node_id, location: self.location, flags: self.flags, when_keyword_loc: self.when_keyword_loc, conditions: self.conditions, then_keyword_loc: self.then_keyword_loc, statements: self.statements) WhenNode.new(source, node_id, location, flags, when_keyword_loc, conditions, then_keyword_loc, statements) end
Creates a copy of self with the given fields, using self as the template.
:call-seq: copy(**fields) -> WhenNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?when_keyword_loc: Location, ?conditions: Array, ?then_keyword_loc: Location?, ?statements: StatementsNode?) -> WhenNode
() → Enumerator[node, void]
() { (node) → void } → void
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32787 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? conditions.each { |node| yield node } if (statements = self.statements); yield statements; end end
See Node.each_child_node.
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
Repository
Methods related to Relocation.
Public Instance Methods
(_Repository repository) → Relocation::Entry?
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32911 def save_then_keyword_loc(repository) repository.enter(node_id, :then_keyword_loc) unless @then_keyword_loc.nil? end
Save the then_keyword_loc location using the given saved source so that it can be retrieved later.
:category: Repository Save the then_keyword_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry?
(_Repository repository) → Relocation::Entry
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32873 def save_when_keyword_loc(repository) repository.enter(node_id, :when_keyword_loc) end
Save the when_keyword_loc location using the given saved source so that it can be retrieved later.
:category: Repository Save the when_keyword_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
Slicing
Public Instance Methods
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32942 def then_keyword then_keyword_loc&.slice end
Slice the location of then_keyword_loc from the source.
:call-seq: then_keyword -> String | nil
Slice the location of then_keyword_loc from the source.
: () -> String?
Source
# File vendor/bundle/ruby/4.0.0/gems/prism-2.1.0-x86_64-linux-gnu/lib/prism/node.rb, line 32932 def when_keyword when_keyword_loc.slice end
Slice the location of when_keyword_loc from the source.
:call-seq: when_keyword -> String
Slice the location of when_keyword_loc from the source.
: () -> String