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

Returns a new instance of IVar.



6755
6756
6757
6758
6759
# File 'lib/syntax_tree/node.rb', line 6755

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6753
6754
6755
# File 'lib/syntax_tree/node.rb', line 6753

def comments
  @comments
end

#valueObject (readonly)

String

the name of the instance variable



6750
6751
6752
# File 'lib/syntax_tree/node.rb', line 6750

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

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



6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
# File 'lib/syntax_tree/node.rb', line 6769

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



6782
6783
6784
# File 'lib/syntax_tree/node.rb', line 6782

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

#format(q) ⇒ Object



6786
6787
6788
# File 'lib/syntax_tree/node.rb', line 6786

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