Class: YARP::InstanceVariableOrWriteNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::InstanceVariableOrWriteNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents the use of the ‘||=` operator for assignment to an instance variable.
@target ||= value
^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#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) -> InstanceVariableOrWriteNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(name, name_loc, operator_loc, value, location) ⇒ InstanceVariableOrWriteNode
constructor
def initialize: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#operator ⇒ Object
def operator: () -> String.
Constructor Details
#initialize(name, name_loc, operator_loc, value, location) ⇒ InstanceVariableOrWriteNode
def initialize: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void
5501 5502 5503 5504 5505 5506 5507 |
# File 'lib/yarp/node.rb', line 5501 def initialize(name, name_loc, operator_loc, value, location) @name = name @name_loc = name_loc @operator_loc = operator_loc @value = value @location = location end |
Instance Attribute Details
#name ⇒ Object (readonly)
attr_reader name: Symbol
5489 5490 5491 |
# File 'lib/yarp/node.rb', line 5489 def name @name end |
#name_loc ⇒ Object (readonly)
attr_reader name_loc: Location
5492 5493 5494 |
# File 'lib/yarp/node.rb', line 5492 def name_loc @name_loc end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location
5495 5496 5497 |
# File 'lib/yarp/node.rb', line 5495 def operator_loc @operator_loc end |
#value ⇒ Object (readonly)
attr_reader value: Node
5498 5499 5500 |
# File 'lib/yarp/node.rb', line 5498 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
5510 5511 5512 |
# File 'lib/yarp/node.rb', line 5510 def accept(visitor) visitor.visit_instance_variable_or_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
5515 5516 5517 |
# File 'lib/yarp/node.rb', line 5515 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
5520 5521 5522 |
# File 'lib/yarp/node.rb', line 5520 def comment_targets [name_loc, operator_loc, value] end |
#copy(**params) ⇒ Object
def copy: (**params) -> InstanceVariableOrWriteNode
5525 5526 5527 5528 5529 5530 5531 5532 5533 |
# File 'lib/yarp/node.rb', line 5525 def copy(**params) InstanceVariableOrWriteNode.new( params.fetch(:name) { name }, params.fetch(:name_loc) { name_loc }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:value) { value }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
5539 5540 5541 |
# File 'lib/yarp/node.rb', line 5539 def deconstruct_keys(keys) { name: name, name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
5548 5549 5550 5551 5552 5553 5554 5555 5556 |
# File 'lib/yarp/node.rb', line 5548 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── name: #{name.inspect}\n" 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.to_str end |
#operator ⇒ Object
def operator: () -> String
5544 5545 5546 |
# File 'lib/yarp/node.rb', line 5544 def operator operator_loc.slice end |