Class: YARP::OrNode

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 `or` keyword.

left or right
^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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



7674
7675
7676
7677
7678
7679
# File 'lib/yarp/node.rb', line 7674

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



7665
7666
7667
# File 'lib/yarp/node.rb', line 7665

def left
  @left
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



7671
7672
7673
# File 'lib/yarp/node.rb', line 7671

def operator_loc
  @operator_loc
end

#rightObject (readonly)

attr_reader right: Node



7668
7669
7670
# File 'lib/yarp/node.rb', line 7668

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



7682
7683
7684
# File 'lib/yarp/node.rb', line 7682

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

#child_nodesObject Also known as: deconstruct

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



7687
7688
7689
# File 'lib/yarp/node.rb', line 7687

def child_nodes
  [left, right]
end

#comment_targetsObject

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



7692
7693
7694
# File 'lib/yarp/node.rb', line 7692

def comment_targets
  [left, right, operator_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> OrNode



7697
7698
7699
7700
7701
7702
7703
7704
# File 'lib/yarp/node.rb', line 7697

def copy(**params)
  OrNode.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]



7710
7711
7712
# File 'lib/yarp/node.rb', line 7710

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

#inspect(inspector = NodeInspector.new) ⇒ Object



7719
7720
7721
7722
7723
7724
7725
7726
7727
# File 'lib/yarp/node.rb', line 7719

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



7715
7716
7717
# File 'lib/yarp/node.rb', line 7715

def operator
  operator_loc.slice
end