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.



8412
8413
8414
8415
8416
# File 'lib/syntax_tree/node.rb', line 8412

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8410
8411
8412
# File 'lib/syntax_tree/node.rb', line 8410

def comments
  @comments
end

#valueObject (readonly)

String

the period



8407
8408
8409
# File 'lib/syntax_tree/node.rb', line 8407

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



8418
8419
8420
# File 'lib/syntax_tree/node.rb', line 8418

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

#child_nodesObject Also known as: deconstruct



8422
8423
8424
# File 'lib/syntax_tree/node.rb', line 8422

def child_nodes
  []
end

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



8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
# File 'lib/syntax_tree/node.rb', line 8426

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



8439
8440
8441
# File 'lib/syntax_tree/node.rb', line 8439

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

#format(q) ⇒ Object



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

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