Class: SyntaxTree::IVar

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

Overview

IVar represents an instance variable literal.

@variable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ IVar

Returns a new instance of IVar.



7611
7612
7613
7614
7615
# File 'lib/syntax_tree.rb', line 7611

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7609
7610
7611
# File 'lib/syntax_tree.rb', line 7609

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7606
7607
7608
# File 'lib/syntax_tree.rb', line 7606

def location
  @location
end

#valueObject (readonly)

String

the name of the instance variable



7603
7604
7605
# File 'lib/syntax_tree.rb', line 7603

def value
  @value
end

Instance Method Details

#child_nodesObject



7617
7618
7619
# File 'lib/syntax_tree.rb', line 7617

def child_nodes
  []
end

#format(q) ⇒ Object



7621
7622
7623
# File 'lib/syntax_tree.rb', line 7621

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

#pretty_print(q) ⇒ Object



7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
# File 'lib/syntax_tree.rb', line 7625

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("ivar")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



7636
7637
7638
7639
7640
# File 'lib/syntax_tree.rb', line 7636

def to_json(*opts)
  { type: :ivar, value: value, loc: location, cmts: comments }.to_json(
    *opts
  )
end