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

Constructor Details

#initialize(value:, location:) ⇒ VCall

Returns a new instance of VCall.



11723
11724
11725
11726
11727
# File 'lib/syntax_tree/node.rb', line 11723

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11721
11722
11723
# File 'lib/syntax_tree/node.rb', line 11721

def comments
  @comments
end

#valueObject (readonly)

Ident

the value of this expression



11718
11719
11720
# File 'lib/syntax_tree/node.rb', line 11718

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



11758
11759
11760
# File 'lib/syntax_tree/node.rb', line 11758

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

#accept(visitor) ⇒ Object



11729
11730
11731
# File 'lib/syntax_tree/node.rb', line 11729

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

#access_control?Boolean

Returns:

  • (Boolean)


11762
11763
11764
# File 'lib/syntax_tree/node.rb', line 11762

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

#arityObject



11766
11767
11768
# File 'lib/syntax_tree/node.rb', line 11766

def arity
  0
end

#child_nodesObject Also known as: deconstruct



11733
11734
11735
# File 'lib/syntax_tree/node.rb', line 11733

def child_nodes
  [value]
end

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



11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
# File 'lib/syntax_tree/node.rb', line 11737

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



11750
11751
11752
# File 'lib/syntax_tree/node.rb', line 11750

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

#format(q) ⇒ Object



11754
11755
11756
# File 'lib/syntax_tree/node.rb', line 11754

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