Class: SyntaxTree::VCall

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

Overview

VCall represent any plain named object with Ruby that could be either a local variable or a method call.

variable

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:) ⇒ VCall

Returns a new instance of VCall.



11546
11547
11548
11549
11550
# File 'lib/syntax_tree/node.rb', line 11546

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11544
11545
11546
# File 'lib/syntax_tree/node.rb', line 11544

def comments
  @comments
end

#valueObject (readonly)

Ident

the value of this expression



11541
11542
11543
# File 'lib/syntax_tree/node.rb', line 11541

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



11581
11582
11583
# File 'lib/syntax_tree/node.rb', line 11581

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

#accept(visitor) ⇒ Object



11552
11553
11554
# File 'lib/syntax_tree/node.rb', line 11552

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

#access_control?Boolean

Returns:

  • (Boolean)


11585
11586
11587
# File 'lib/syntax_tree/node.rb', line 11585

def access_control?
  @access_control ||= %w[private protected public].include?(value.value)
end

#child_nodesObject Also known as: deconstruct



11556
11557
11558
# File 'lib/syntax_tree/node.rb', line 11556

def child_nodes
  [value]
end

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



11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
# File 'lib/syntax_tree/node.rb', line 11560

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

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

#deconstruct_keys(_keys) ⇒ Object



11573
11574
11575
# File 'lib/syntax_tree/node.rb', line 11573

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

#format(q) ⇒ Object



11577
11578
11579
# File 'lib/syntax_tree/node.rb', line 11577

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