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

Constructor Details

#initialize(value:, location:) ⇒ IVar



6764
6765
6766
6767
6768
# File 'lib/syntax_tree/node.rb', line 6764

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6762
6763
6764
# File 'lib/syntax_tree/node.rb', line 6762

def comments
  @comments
end

#valueObject (readonly)

String

the name of the instance variable



6759
6760
6761
# File 'lib/syntax_tree/node.rb', line 6759

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



6799
6800
6801
# File 'lib/syntax_tree/node.rb', line 6799

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

#accept(visitor) ⇒ Object



6770
6771
6772
# File 'lib/syntax_tree/node.rb', line 6770

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

#child_nodesObject Also known as: deconstruct



6774
6775
6776
# File 'lib/syntax_tree/node.rb', line 6774

def child_nodes
  []
end

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



6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
# File 'lib/syntax_tree/node.rb', line 6778

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



6791
6792
6793
# File 'lib/syntax_tree/node.rb', line 6791

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

#format(q) ⇒ Object



6795
6796
6797
# File 'lib/syntax_tree/node.rb', line 6795

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