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.



6882
6883
6884
6885
6886
# File 'lib/syntax_tree/node.rb', line 6882

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6880
6881
6882
# File 'lib/syntax_tree/node.rb', line 6880

def comments
  @comments
end

#valueObject (readonly)

String

the name of the instance variable



6877
6878
6879
# File 'lib/syntax_tree/node.rb', line 6877

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



6917
6918
6919
# File 'lib/syntax_tree/node.rb', line 6917

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

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



6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
# File 'lib/syntax_tree/node.rb', line 6896

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



6909
6910
6911
# File 'lib/syntax_tree/node.rb', line 6909

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

#format(q) ⇒ Object



6913
6914
6915
# File 'lib/syntax_tree/node.rb', line 6913

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