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.



11739
11740
11741
11742
11743
# File 'lib/syntax_tree/node.rb', line 11739

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11737
11738
11739
# File 'lib/syntax_tree/node.rb', line 11737

def comments
  @comments
end

#valueObject (readonly)

Ident

the value of this expression



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

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



11774
11775
11776
# File 'lib/syntax_tree/node.rb', line 11774

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

#accept(visitor) ⇒ Object



11745
11746
11747
# File 'lib/syntax_tree/node.rb', line 11745

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

#access_control?Boolean

Returns:

  • (Boolean)


11778
11779
11780
# File 'lib/syntax_tree/node.rb', line 11778

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

#arityObject



11782
11783
11784
# File 'lib/syntax_tree/node.rb', line 11782

def arity
  0
end

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [value]
end

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



11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
# File 'lib/syntax_tree/node.rb', line 11753

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



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

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

#format(q) ⇒ Object



11770
11771
11772
# File 'lib/syntax_tree/node.rb', line 11770

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