Class: SyntaxTree::Period

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Period represents the use of the . operator. It is usually found in method calls.

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(value:, location:) ⇒ Period

Returns a new instance of Period.



8575
8576
8577
8578
8579
# File 'lib/syntax_tree/node.rb', line 8575

def initialize(value:, location:)
  @value = value
  @location = location
  @comments = []
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8573
8574
8575
# File 'lib/syntax_tree/node.rb', line 8573

def comments
  @comments
end

#valueObject (readonly)

String

the period



8570
8571
8572
# File 'lib/syntax_tree/node.rb', line 8570

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



8610
8611
8612
# File 'lib/syntax_tree/node.rb', line 8610

def ===(other)
  other.is_a?(Period) && value === other.value
end

#accept(visitor) ⇒ Object



8581
8582
8583
# File 'lib/syntax_tree/node.rb', line 8581

def accept(visitor)
  visitor.visit_period(self)
end

#child_nodesObject Also known as: deconstruct



8585
8586
8587
# File 'lib/syntax_tree/node.rb', line 8585

def child_nodes
  []
end

#copy(value: nil, location: nil) ⇒ Object



8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
# File 'lib/syntax_tree/node.rb', line 8589

def copy(value: nil, location: nil)
  node =
    Period.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



8602
8603
8604
# File 'lib/syntax_tree/node.rb', line 8602

def deconstruct_keys(_keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



8606
8607
8608
# File 'lib/syntax_tree/node.rb', line 8606

def format(q)
  q.text(value)
end