Class: YARP::MatchPredicateNode

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

Overview

Represents the use of the modifier ‘in` operator.

foo in bar
^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, pattern, operator_loc, location) ⇒ MatchPredicateNode

def initialize: (value: Node, pattern: Node, operator_loc: Location, location: Location) -> void



6912
6913
6914
6915
6916
6917
# File 'lib/yarp/node.rb', line 6912

def initialize(value, pattern, operator_loc, location)
  @value = value
  @pattern = pattern
  @operator_loc = operator_loc
  @location = location
end

Instance Attribute Details

#operator_locObject (readonly)

attr_reader operator_loc: Location



6909
6910
6911
# File 'lib/yarp/node.rb', line 6909

def operator_loc
  @operator_loc
end

#patternObject (readonly)

attr_reader pattern: Node



6906
6907
6908
# File 'lib/yarp/node.rb', line 6906

def pattern
  @pattern
end

#valueObject (readonly)

attr_reader value: Node



6903
6904
6905
# File 'lib/yarp/node.rb', line 6903

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



6920
6921
6922
# File 'lib/yarp/node.rb', line 6920

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

#child_nodesObject Also known as: deconstruct

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



6925
6926
6927
# File 'lib/yarp/node.rb', line 6925

def child_nodes
  [value, pattern]
end

#comment_targetsObject

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



6930
6931
6932
# File 'lib/yarp/node.rb', line 6930

def comment_targets
  [value, pattern, operator_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> MatchPredicateNode



6935
6936
6937
6938
6939
6940
6941
6942
# File 'lib/yarp/node.rb', line 6935

def copy(**params)
  MatchPredicateNode.new(
    params.fetch(:value) { value },
    params.fetch(:pattern) { pattern },
    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]



6948
6949
6950
# File 'lib/yarp/node.rb', line 6948

def deconstruct_keys(keys)
  { value: value, pattern: pattern, operator_loc: operator_loc, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



6957
6958
6959
6960
6961
6962
6963
6964
6965
# File 'lib/yarp/node.rb', line 6957

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

#operatorObject

def operator: () -> String



6953
6954
6955
# File 'lib/yarp/node.rb', line 6953

def operator
  operator_loc.slice
end