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, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:) ⇒ Period

Returns a new instance of Period.



8447
8448
8449
8450
8451
# File 'lib/syntax_tree/node.rb', line 8447

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8445
8446
8447
# File 'lib/syntax_tree/node.rb', line 8445

def comments
  @comments
end

#valueObject (readonly)

String

the period



8442
8443
8444
# File 'lib/syntax_tree/node.rb', line 8442

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



8482
8483
8484
# File 'lib/syntax_tree/node.rb', line 8482

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

#accept(visitor) ⇒ Object



8453
8454
8455
# File 'lib/syntax_tree/node.rb', line 8453

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

#child_nodesObject Also known as: deconstruct



8457
8458
8459
# File 'lib/syntax_tree/node.rb', line 8457

def child_nodes
  []
end

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



8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
# File 'lib/syntax_tree/node.rb', line 8461

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



8474
8475
8476
# File 'lib/syntax_tree/node.rb', line 8474

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

#format(q) ⇒ Object



8478
8479
8480
# File 'lib/syntax_tree/node.rb', line 8478

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