Class: YARP::WhenNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::WhenNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents the use of the ‘when` keyword within a case statement.
case true
when true
^^^^^^^^^
end
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
attr_reader conditions: Array.
-
#keyword_loc ⇒ Object
readonly
attr_reader keyword_loc: Location.
-
#statements ⇒ Object
readonly
attr_reader statements: StatementsNode?.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#copy(**params) ⇒ Object
def copy: (**params) -> WhenNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(keyword_loc, conditions, statements, location) ⇒ WhenNode
constructor
def initialize: (keyword_loc: Location, conditions: Array, statements: StatementsNode?, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#keyword ⇒ Object
def keyword: () -> String.
Constructor Details
#initialize(keyword_loc, conditions, statements, location) ⇒ WhenNode
def initialize: (keyword_loc: Location, conditions: Array, statements: StatementsNode?, location: Location) -> void
10219 10220 10221 10222 10223 10224 |
# File 'lib/yarp/node.rb', line 10219 def initialize(keyword_loc, conditions, statements, location) @keyword_loc = keyword_loc @conditions = conditions @statements = statements @location = location end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
attr_reader conditions: Array
10213 10214 10215 |
# File 'lib/yarp/node.rb', line 10213 def conditions @conditions end |
#keyword_loc ⇒ Object (readonly)
attr_reader keyword_loc: Location
10210 10211 10212 |
# File 'lib/yarp/node.rb', line 10210 def keyword_loc @keyword_loc end |
#statements ⇒ Object (readonly)
attr_reader statements: StatementsNode?
10216 10217 10218 |
# File 'lib/yarp/node.rb', line 10216 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
10227 10228 10229 |
# File 'lib/yarp/node.rb', line 10227 def accept(visitor) visitor.visit_when_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
10232 10233 10234 |
# File 'lib/yarp/node.rb', line 10232 def child_nodes [*conditions, statements] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
10237 10238 10239 |
# File 'lib/yarp/node.rb', line 10237 def comment_targets [keyword_loc, *conditions, *statements] end |
#copy(**params) ⇒ Object
def copy: (**params) -> WhenNode
10242 10243 10244 10245 10246 10247 10248 10249 |
# File 'lib/yarp/node.rb', line 10242 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) ⇒ Object
10255 10256 10257 |
# File 'lib/yarp/node.rb', line 10255 def deconstruct_keys(keys) { keyword_loc: keyword_loc, conditions: conditions, statements: statements, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 |
# File 'lib/yarp/node.rb', line 10264 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 ⇒ Object
def keyword: () -> String
10260 10261 10262 |
# File 'lib/yarp/node.rb', line 10260 def keyword keyword_loc.slice end |