Class: YARP::AndNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents the use of the ‘&&` operator or the `and` keyword.

left and right
^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, right, operator_loc, location) ⇒ AndNode

def initialize: (left: Node, right: Node, operator_loc: Location, location: Location) -> void



166
167
168
169
170
171
# File 'lib/yarp/node.rb', line 166

def initialize(left, right, operator_loc, location)
  @left = left
  @right = right
  @operator_loc = operator_loc
  @location = location
end

Instance Attribute Details

#leftObject (readonly)

attr_reader left: Node



157
158
159
# File 'lib/yarp/node.rb', line 157

def left
  @left
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



163
164
165
# File 'lib/yarp/node.rb', line 163

def operator_loc
  @operator_loc
end

#rightObject (readonly)

attr_reader right: Node



160
161
162
# File 'lib/yarp/node.rb', line 160

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



174
175
176
# File 'lib/yarp/node.rb', line 174

def accept(visitor)
  visitor.visit_and_node(self)
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



179
180
181
# File 'lib/yarp/node.rb', line 179

def child_nodes
  [left, right]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



184
185
186
# File 'lib/yarp/node.rb', line 184

def comment_targets
  [left, right, operator_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> AndNode



189
190
191
192
193
194
195
196
# File 'lib/yarp/node.rb', line 189

def copy(**params)
  AndNode.new(
    params.fetch(:left) { left },
    params.fetch(:right) { right },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



202
203
204
# File 'lib/yarp/node.rb', line 202

def deconstruct_keys(keys)
  { left: left, right: right, operator_loc: operator_loc, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



211
212
213
214
215
216
217
218
219
# File 'lib/yarp/node.rb', line 211

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── left:\n"
  inspector << inspector.child_node(left, "")
  inspector << "├── right:\n"
  inspector << inspector.child_node(right, "")
  inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector.to_str
end

#operatorObject

def operator: () -> String



207
208
209
# File 'lib/yarp/node.rb', line 207

def operator
  operator_loc.slice
end