Class: YARP::ConstantOrWriteNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::ConstantOrWriteNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents the use of the ‘||=` operator for assignment to a constant.
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) -> ConstantOrWriteNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(name, name_loc, operator_loc, value, location) ⇒ ConstantOrWriteNode
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) ⇒ ConstantOrWriteNode
def initialize: (name: Symbol, name_loc: Location, operator_loc: Location, value: Node, location: Location) -> void
2717 2718 2719 2720 2721 2722 2723 |
# File 'lib/yarp/node.rb', line 2717 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
2705 2706 2707 |
# File 'lib/yarp/node.rb', line 2705 def name @name end |
#name_loc ⇒ Object (readonly)
attr_reader name_loc: Location
2708 2709 2710 |
# File 'lib/yarp/node.rb', line 2708 def name_loc @name_loc end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location
2711 2712 2713 |
# File 'lib/yarp/node.rb', line 2711 def operator_loc @operator_loc end |
#value ⇒ Object (readonly)
attr_reader value: Node
2714 2715 2716 |
# File 'lib/yarp/node.rb', line 2714 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
2726 2727 2728 |
# File 'lib/yarp/node.rb', line 2726 def accept(visitor) visitor.visit_constant_or_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
2731 2732 2733 |
# File 'lib/yarp/node.rb', line 2731 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
2736 2737 2738 |
# File 'lib/yarp/node.rb', line 2736 def comment_targets [name_loc, operator_loc, value] end |
#copy(**params) ⇒ Object
def copy: (**params) -> ConstantOrWriteNode
2741 2742 2743 2744 2745 2746 2747 2748 2749 |
# File 'lib/yarp/node.rb', line 2741 def copy(**params) ConstantOrWriteNode.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
2755 2756 2757 |
# File 'lib/yarp/node.rb', line 2755 def deconstruct_keys(keys) { name: name, name_loc: name_loc, operator_loc: operator_loc, value: value, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
2764 2765 2766 2767 2768 2769 2770 2771 2772 |
# File 'lib/yarp/node.rb', line 2764 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
2760 2761 2762 |
# File 'lib/yarp/node.rb', line 2760 def operator operator_loc.slice end |