Class: YARP::AssocNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::AssocNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents a hash key/value pair.
{ a => b }
^^^^^^
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
attr_reader key: Node.
-
#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) -> AssocNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(key, value, operator_loc, location) ⇒ AssocNode
constructor
def initialize: (key: Node, value: Node?, operator_loc: Location?, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#operator ⇒ Object
def operator: () -> String?.
Constructor Details
#initialize(key, value, operator_loc, location) ⇒ AssocNode
def initialize: (key: Node, value: Node?, operator_loc: Location?, location: Location) -> void
478 479 480 481 482 483 |
# File 'lib/yarp/node.rb', line 478 def initialize(key, value, operator_loc, location) @key = key @value = value @operator_loc = operator_loc @location = location end |
Instance Attribute Details
#key ⇒ Object (readonly)
attr_reader key: Node
469 470 471 |
# File 'lib/yarp/node.rb', line 469 def key @key end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location?
475 476 477 |
# File 'lib/yarp/node.rb', line 475 def operator_loc @operator_loc end |
#value ⇒ Object (readonly)
attr_reader value: Node?
472 473 474 |
# File 'lib/yarp/node.rb', line 472 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
486 487 488 |
# File 'lib/yarp/node.rb', line 486 def accept(visitor) visitor.visit_assoc_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
491 492 493 |
# File 'lib/yarp/node.rb', line 491 def child_nodes [key, value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
496 497 498 |
# File 'lib/yarp/node.rb', line 496 def comment_targets [key, *value, *operator_loc] end |
#copy(**params) ⇒ Object
def copy: (**params) -> AssocNode
501 502 503 504 505 506 507 508 |
# File 'lib/yarp/node.rb', line 501 def copy(**params) AssocNode.new( params.fetch(:key) { key }, params.fetch(:value) { value }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
514 515 516 |
# File 'lib/yarp/node.rb', line 514 def deconstruct_keys(keys) { key: key, value: value, operator_loc: operator_loc, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/yarp/node.rb', line 523 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── key:\n" inspector << inspector.child_node(key, "│ ") if (value = self.value).nil? inspector << "├── value: ∅\n" else inspector << "├── value:\n" inspector << value.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n" inspector.to_str end |
#operator ⇒ Object
def operator: () -> String?
519 520 521 |
# File 'lib/yarp/node.rb', line 519 def operator operator_loc&.slice end |