Class: YARP::LocalVariableOrWriteNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::LocalVariableOrWriteNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents the use of the ‘||=` operator for assignment to a local variable.
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_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].
-
#copy(**params) ⇒ Object
def copy: (**params) -> LocalVariableOrWriteNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(name_loc, operator_loc, value, name, depth, location) ⇒ LocalVariableOrWriteNode
constructor
def initialize: (name_loc: Location, operator_loc: Location, value: Node, name: Symbol, depth: Integer, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#operator ⇒ Object
def operator: () -> String.
Constructor Details
#initialize(name_loc, operator_loc, value, name, depth, location) ⇒ LocalVariableOrWriteNode
def initialize: (name_loc: Location, operator_loc: Location, value: Node, name: Symbol, depth: Integer, location: Location) -> void
6636 6637 6638 6639 6640 6641 6642 6643 |
# File 'lib/yarp/node.rb', line 6636 def initialize(name_loc, operator_loc, value, name, depth, location) @name_loc = name_loc @operator_loc = operator_loc @value = value @name = name @depth = depth @location = location end |
Instance Attribute Details
#depth ⇒ Object (readonly)
attr_reader depth: Integer
6633 6634 6635 |
# File 'lib/yarp/node.rb', line 6633 def depth @depth end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
6630 6631 6632 |
# File 'lib/yarp/node.rb', line 6630 def name @name end |
#name_loc ⇒ Object (readonly)
attr_reader name_loc: Location
6621 6622 6623 |
# File 'lib/yarp/node.rb', line 6621 def name_loc @name_loc end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location
6624 6625 6626 |
# File 'lib/yarp/node.rb', line 6624 def operator_loc @operator_loc end |
#value ⇒ Object (readonly)
attr_reader value: Node
6627 6628 6629 |
# File 'lib/yarp/node.rb', line 6627 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
6646 6647 6648 |
# File 'lib/yarp/node.rb', line 6646 def accept(visitor) visitor.visit_local_variable_or_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
6651 6652 6653 |
# File 'lib/yarp/node.rb', line 6651 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
6656 6657 6658 |
# File 'lib/yarp/node.rb', line 6656 def comment_targets [name_loc, operator_loc, value] end |
#copy(**params) ⇒ Object
def copy: (**params) -> LocalVariableOrWriteNode
6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 |
# File 'lib/yarp/node.rb', line 6661 def copy(**params) LocalVariableOrWriteNode.new( params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:name) { name }, params.fetch(:depth) { depth }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
6676 6677 6678 |
# File 'lib/yarp/node.rb', line 6676 def deconstruct_keys(keys) { name_loc: name_loc, operator_loc: operator_loc, value: value, name: name, depth: depth, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 |
# File 'lib/yarp/node.rb', line 6685 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 << "└── depth: #{depth.inspect}\n" inspector.to_str end |
#operator ⇒ Object
def operator: () -> String
6681 6682 6683 |
# File 'lib/yarp/node.rb', line 6681 def operator operator_loc.slice end |