Class: Prism::LocalVariableOperatorWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::LocalVariableOperatorWriteNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents assigning to a local variable using an operator that isn’t ‘=`.
target += value
^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
attr_reader depth: Integer.
-
#name ⇒ Object
readonly
attr_reader name: Symbol.
-
#name_loc ⇒ Object
readonly
attr_reader name_loc: Location.
-
#operator ⇒ Object
readonly
attr_reader operator: Symbol.
-
#operator_loc ⇒ Object
readonly
attr_reader operator_loc: Location.
-
#value ⇒ Object
readonly
attr_reader value: Node.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(**params) ⇒ Object
def copy: (**params) -> LocalVariableOperatorWriteNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(name_loc, operator_loc, value, name, operator, depth, location) ⇒ LocalVariableOperatorWriteNode
constructor
def initialize: (name_loc: Location, operator_loc: Location, value: Node, name: Symbol, operator: Symbol, depth: Integer, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform.
Constructor Details
#initialize(name_loc, operator_loc, value, name, operator, depth, location) ⇒ LocalVariableOperatorWriteNode
def initialize: (name_loc: Location, operator_loc: Location, value: Node, name: Symbol, operator: Symbol, depth: Integer, location: Location) -> void
8927 8928 8929 8930 8931 8932 8933 8934 8935 |
# File 'lib/prism/node.rb', line 8927 def initialize(name_loc, operator_loc, value, name, operator, depth, location) @name_loc = name_loc @operator_loc = operator_loc @value = value @name = name @operator = operator @depth = depth @location = location end |
Instance Attribute Details
#depth ⇒ Object (readonly)
attr_reader depth: Integer
8924 8925 8926 |
# File 'lib/prism/node.rb', line 8924 def depth @depth end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
8918 8919 8920 |
# File 'lib/prism/node.rb', line 8918 def name @name end |
#name_loc ⇒ Object (readonly)
attr_reader name_loc: Location
8909 8910 8911 |
# File 'lib/prism/node.rb', line 8909 def name_loc @name_loc end |
#operator ⇒ Object (readonly)
attr_reader operator: Symbol
8921 8922 8923 |
# File 'lib/prism/node.rb', line 8921 def operator @operator end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location
8912 8913 8914 |
# File 'lib/prism/node.rb', line 8912 def operator_loc @operator_loc end |
#value ⇒ Object (readonly)
attr_reader value: Node
8915 8916 8917 |
# File 'lib/prism/node.rb', line 8915 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
8938 8939 8940 |
# File 'lib/prism/node.rb', line 8938 def accept(visitor) visitor.visit_local_variable_operator_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
8943 8944 8945 |
# File 'lib/prism/node.rb', line 8943 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
8953 8954 8955 |
# File 'lib/prism/node.rb', line 8953 def comment_targets [name_loc, operator_loc, value] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
8948 8949 8950 |
# File 'lib/prism/node.rb', line 8948 def compact_child_nodes [value] end |
#copy(**params) ⇒ Object
def copy: (**params) -> LocalVariableOperatorWriteNode
8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 |
# File 'lib/prism/node.rb', line 8958 def copy(**params) LocalVariableOperatorWriteNode.new( params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:name) { name }, params.fetch(:operator) { operator }, params.fetch(:depth) { depth }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
8974 8975 8976 |
# File 'lib/prism/node.rb', line 8974 def deconstruct_keys(keys) { name_loc: name_loc, operator_loc: operator_loc, value: value, name: name, operator: operator, depth: depth, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 |
# File 'lib/prism/node.rb', line 8978 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── name_loc: #{inspector.location(name_loc)}\n" inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" inspector << "├── value:\n" inspector << inspector.child_node(value, "│ ") inspector << "├── name: #{name.inspect}\n" inspector << "├── operator: #{operator.inspect}\n" inspector << "└── depth: #{depth.inspect}\n" inspector.to_str end |
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform. Usually this is done by calling ‘[cls1, cls2].include?(node.class)` or putting the node into a case statement and doing `case node; when cls1; when cls2; end`. Both of these approaches are relatively slow because of the constant lookups, method calls, and/or array allocations.
Instead, you can call #type, which will return to you a symbol that you can use for comparison. This is faster than the other approaches because it uses a single integer comparison, but also because if you’re on CRuby you can take advantage of the fact that case statements with all symbol keys will use a jump table.
def type: () -> Symbol
9004 9005 9006 |
# File 'lib/prism/node.rb', line 9004 def type :local_variable_operator_write_node end |