Class: SyntaxTree::IVar

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

Overview

IVar represents an instance variable literal.

@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:) ⇒ IVar

Returns a new instance of IVar.



6858
6859
6860
6861
6862
# File 'lib/syntax_tree/node.rb', line 6858

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6856
6857
6858
# File 'lib/syntax_tree/node.rb', line 6856

def comments
  @comments
end

#valueObject (readonly)

String

the name of the instance variable



6853
6854
6855
# File 'lib/syntax_tree/node.rb', line 6853

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



6893
6894
6895
# File 'lib/syntax_tree/node.rb', line 6893

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

#accept(visitor) ⇒ Object



6864
6865
6866
# File 'lib/syntax_tree/node.rb', line 6864

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

#child_nodesObject Also known as: deconstruct



6868
6869
6870
# File 'lib/syntax_tree/node.rb', line 6868

def child_nodes
  []
end

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



6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
# File 'lib/syntax_tree/node.rb', line 6872

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

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

#deconstruct_keys(_keys) ⇒ Object



6885
6886
6887
# File 'lib/syntax_tree/node.rb', line 6885

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

#format(q) ⇒ Object



6889
6890
6891
# File 'lib/syntax_tree/node.rb', line 6889

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