Class: YARP::ClassVariableOrWriteNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::ClassVariableOrWriteNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents the use of the ‘||=` operator for assignment to a class 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) -> ClassVariableOrWriteNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(name, name_loc, operator_loc, value, location) ⇒ ClassVariableOrWriteNode
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) ⇒ ClassVariableOrWriteNode
def initialize: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void
2308 2309 2310 2311 2312 2313 2314 |
# File 'lib/yarp/node.rb', line 2308 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
2296 2297 2298 |
# File 'lib/yarp/node.rb', line 2296 def name @name end |
#name_loc ⇒ Object (readonly)
attr_reader name_loc: Location
2299 2300 2301 |
# File 'lib/yarp/node.rb', line 2299 def name_loc @name_loc end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location
2302 2303 2304 |
# File 'lib/yarp/node.rb', line 2302 def operator_loc @operator_loc end |
#value ⇒ Object (readonly)
attr_reader value: Node
2305 2306 2307 |
# File 'lib/yarp/node.rb', line 2305 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
2317 2318 2319 |
# File 'lib/yarp/node.rb', line 2317 def accept(visitor) visitor.visit_class_variable_or_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
2322 2323 2324 |
# File 'lib/yarp/node.rb', line 2322 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
2327 2328 2329 |
# File 'lib/yarp/node.rb', line 2327 def comment_targets [name_loc, operator_loc, value] end |
#copy(**params) ⇒ Object
def copy: (**params) -> ClassVariableOrWriteNode
2332 2333 2334 2335 2336 2337 2338 2339 2340 |
# File 'lib/yarp/node.rb', line 2332 def copy(**params) ClassVariableOrWriteNode.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
2346 2347 2348 |
# File 'lib/yarp/node.rb', line 2346 def deconstruct_keys(keys) { name: name, name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
2355 2356 2357 2358 2359 2360 2361 2362 2363 |
# File 'lib/yarp/node.rb', line 2355 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
2351 2352 2353 |
# File 'lib/yarp/node.rb', line 2351 def operator operator_loc.slice end |