Class: Prism::OrNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::OrNode
- 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 or keyword.
left or right
^^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :or_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) ⇒ OrNode
:call-seq: copy(**fields) -> OrNode.
-
#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) ⇒ OrNode
constructor
Initialize a new OrNode 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 ⇒ :or_node
See
Node#type.
Constructor Details
#initialize(source, node_id, location, flags, left, right, operator_loc) ⇒ OrNode
Initialize a new OrNode node.
: (Source source, Integer node_id, Location location, Integer flags, Prism::node left, Prism::node right, Location operator_loc) -> void
25866 25867 25868 25869 25870 25871 25872 25873 25874 |
# File 'lib/prism/node.rb', line 25866 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 ⇒ :or_node
See Node.type.
: () -> :or_node
25957 25958 25959 |
# File 'lib/prism/node.rb', line 25957 def self.type :or_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
26052 26053 26054 26055 26056 26057 |
# File 'lib/prism/node.rb', line 26052 def ===(other) # :nodoc: other.is_a?(OrNode) && (left === other.left) && (right === other.right) && (operator_loc.nil? == other.operator_loc.nil?) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
25890 25891 25892 |
# File 'lib/prism/node.rb', line 25890 def accept(visitor) visitor.visit_or_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
25897 25898 25899 |
# File 'lib/prism/node.rb', line 25897 def child_nodes [left, right] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
25915 25916 25917 |
# File 'lib/prism/node.rb', line 25915 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) ⇒ OrNode
:call-seq:
copy(**fields) -> OrNode
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) -> OrNode
25925 25926 25927 |
# File 'lib/prism/node.rb', line 25925 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) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
25932 25933 25934 25935 25936 25937 25938 25939 25940 25941 25942 25943 25944 25945 |
# File 'lib/prism/node.rb', line 25932 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
25905 25906 25907 25908 25909 25910 |
# File 'lib/prism/node.rb', line 25905 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield left yield right end |
#inspect ⇒ String
: () -> String
25962 25963 25964 |
# File 'lib/prism/node.rb', line 25962 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 or right
^^^^
1 || 2
^
: () -> Prism::node
25984 25985 25986 |
# File 'lib/prism/node.rb', line 25984 def left @left end |
#operator ⇒ String
:call-seq:
operator -> String
Slice the location of operator_loc from the source.
: () -> String
26045 26046 26047 |
# File 'lib/prism/node.rb', line 26045 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
The Location of the or keyword or the || operator.
left or right
^^
: () -> Location
26022 26023 26024 26025 26026 |
# File 'lib/prism/node.rb', line 26022 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 or 2
^
: () -> Prism::node
26004 26005 26006 |
# File 'lib/prism/node.rb', line 26004 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
26033 26034 26035 |
# File 'lib/prism/node.rb', line 26033 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ :or_node
See Node#type.
: () -> :or_node
25950 25951 25952 |
# File 'lib/prism/node.rb', line 25950 def type :or_node end |