Class: Prism::AndNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::AndNode
- Defined in:
- lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c
Overview
Represents the use of the && operator or the and keyword.
left and right
^^^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :and_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc) ⇒ AndNode
:call-seq: copy(**fields) -> AndNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#initialize(source, node_id, location, flags, left, right, operator_loc) ⇒ AndNode
constructor
Initialize a new AndNode node.
-
#inspect ⇒ String
: () -> String.
-
#left ⇒ Prism::node
:call-seq: left -> Node.
-
#operator ⇒ String
:call-seq: operator -> String.
-
#operator_loc ⇒ Location
:category: Locations :call-seq: operator_loc -> Location.
-
#right ⇒ Prism::node
:call-seq: right -> Node.
-
#save_operator_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ :and_node
See
Node#type.
Constructor Details
#initialize(source, node_id, location, flags, left, right, operator_loc) ⇒ AndNode
Initialize a new AndNode node.
: (Source source, Integer node_id, Location location, Integer flags, Prism::node left, Prism::node right, Location operator_loc) -> void
1057 1058 1059 1060 1061 1062 1063 1064 1065 |
# File 'lib/prism/node.rb', line 1057 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 |
Class Method Details
.type ⇒ :and_node
See Node.type.
: () -> :and_node
1148 1149 1150 |
# File 'lib/prism/node.rb', line 1148 def self.type :and_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
1243 1244 1245 1246 1247 1248 |
# File 'lib/prism/node.rb', line 1243 def ===(other) # :nodoc: other.is_a?(AndNode) && (left === other.left) && (right === other.right) && (operator_loc.nil? == other.operator_loc.nil?) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
1081 1082 1083 |
# File 'lib/prism/node.rb', line 1081 def accept(visitor) visitor.visit_and_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
1088 1089 1090 |
# File 'lib/prism/node.rb', line 1088 def child_nodes [left, right] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
1106 1107 1108 |
# File 'lib/prism/node.rb', line 1106 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) ⇒ AndNode
:call-seq:
copy(**fields) -> AndNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?left: Prism::node, ?right: Prism::node, ?operator_loc: Location) -> AndNode
1116 1117 1118 |
# File 'lib/prism/node.rb', line 1116 def copy(node_id: self.node_id, location: self.location, flags: self.flags, left: self.left, right: self.right, operator_loc: self.operator_loc) AndNode.new(source, node_id, location, flags, left, right, operator_loc) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 |
# File 'lib/prism/node.rb', line 1123 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location left right operator_loc operator]).each_with_object( {} #: Hash[Symbol, untyped] ) do |key, deconstructed| case key when :node_id then deconstructed[:node_id] = self.node_id when :location then deconstructed[:location] = self.location when :left then deconstructed[:left] = self.left when :right then deconstructed[:right] = self.right when :operator_loc then deconstructed[:operator_loc] = self.operator_loc when :operator then deconstructed[:operator] = self.operator end end end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
1096 1097 1098 1099 1100 1101 |
# File 'lib/prism/node.rb', line 1096 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield left yield right end |
#inspect ⇒ String
: () -> String
1153 1154 1155 |
# File 'lib/prism/node.rb', line 1153 def inspect # :nodoc: InspectVisitor.compose(self) end |
#left ⇒ Prism::node
:call-seq:
left -> Node
Represents the left side of the expression. It can be any non-void expression.
left and right
^^^^
1 && 2
^
: () -> Prism::node
1175 1176 1177 |
# File 'lib/prism/node.rb', line 1175 def left @left end |
#operator ⇒ String
:call-seq:
operator -> String
Slice the location of operator_loc from the source.
: () -> String
1236 1237 1238 |
# File 'lib/prism/node.rb', line 1236 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
The Location of the and keyword or the && operator.
left and right
^^^
: () -> Location
1213 1214 1215 1216 1217 |
# File 'lib/prism/node.rb', line 1213 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#right ⇒ Prism::node
:call-seq:
right -> Node
Represents the right side of the expression.
left && right
^^^^^
1 and 2
^
: () -> Prism::node
1195 1196 1197 |
# File 'lib/prism/node.rb', line 1195 def right @right end |
#save_operator_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the operator_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
1224 1225 1226 |
# File 'lib/prism/node.rb', line 1224 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ :and_node
See Node#type.
: () -> :and_node
1141 1142 1143 |
# File 'lib/prism/node.rb', line 1141 def type :and_node end |