Class: Prism::OrNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::OrNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents the use of the ‘||` operator or the `or` keyword.
left or right
^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Represents the left side of the expression.
-
#right ⇒ Object
readonly
Represents the right side of the expression.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#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].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?left: Prism::node, ?right: Prism::node, ?operator_loc: Location) -> OrNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, left: Prism::node, right: Prism::node, operator_loc: Location }.
-
#initialize(source, node_id, location, flags, left, right, operator_loc) ⇒ OrNode
constructor
Initialize a new OrNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
The location of the ‘or` keyword or the `||` operator.
-
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, left, right, operator_loc) ⇒ OrNode
Initialize a new OrNode node.
14035 14036 14037 14038 14039 14040 14041 14042 14043 |
# File 'lib/prism/node.rb', line 14035 def initialize(source, node_id, location, flags, left, right, operator_loc) @source = source @node_id = node_id @location = location @flags = flags @left = left @right = right @operator_loc = operator_loc end |
Instance Attribute Details
#left ⇒ Object (readonly)
Represents the left side of the expression. It can be any [non-void expression](github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
left or right
^^^^
1 || 2
^
14085 14086 14087 |
# File 'lib/prism/node.rb', line 14085 def left @left end |
#right ⇒ Object (readonly)
Represents the right side of the expression.
left || right
^^^^^
1 or 2
^
14094 14095 14096 |
# File 'lib/prism/node.rb', line 14094 def right @right end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
14128 14129 14130 |
# File 'lib/prism/node.rb', line 14128 def self.type :or_node end |
Instance Method Details
#===(other) ⇒ Object
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
14134 14135 14136 14137 14138 14139 |
# File 'lib/prism/node.rb', line 14134 def ===(other) other.is_a?(OrNode) && (left === other.left) && (right === other.right) && (operator_loc.nil? == other.operator_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
14046 14047 14048 |
# File 'lib/prism/node.rb', line 14046 def accept(visitor) visitor.visit_or_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
14051 14052 14053 |
# File 'lib/prism/node.rb', line 14051 def child_nodes [left, right] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
14061 14062 14063 |
# File 'lib/prism/node.rb', line 14061 def comment_targets [left, right, operator_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
14056 14057 14058 |
# File 'lib/prism/node.rb', line 14056 def compact_child_nodes [left, right] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?left: Prism::node, ?right: Prism::node, ?operator_loc: Location) -> OrNode
14066 14067 14068 |
# File 'lib/prism/node.rb', line 14066 def copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc) OrNode.new(source, node_id, location, flags, left, right, operator_loc) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, left: Prism::node, right: Prism::node, operator_loc: Location }
14074 14075 14076 |
# File 'lib/prism/node.rb', line 14074 def deconstruct_keys(keys) { node_id: node_id, location: location, left: left, right: right, operator_loc: operator_loc } end |
#inspect ⇒ Object
def inspect -> String
14118 14119 14120 |
# File 'lib/prism/node.rb', line 14118 def inspect InspectVisitor.compose(self) end |
#operator ⇒ Object
def operator: () -> String
14113 14114 14115 |
# File 'lib/prism/node.rb', line 14113 def operator operator_loc.slice end |
#operator_loc ⇒ Object
The location of the ‘or` keyword or the `||` operator.
left or right
^^
14100 14101 14102 14103 14104 |
# File 'lib/prism/node.rb', line 14100 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
14108 14109 14110 |
# File 'lib/prism/node.rb', line 14108 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
14123 14124 14125 |
# File 'lib/prism/node.rb', line 14123 def type :or_node end |