Class: SyntaxTree::VarAlias

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

Overview

VarAlias represents when you’re using the alias keyword with global variable arguments.

alias $new $old

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left:, right:, location:, comments: []) ⇒ VarAlias

Returns a new instance of VarAlias.



12651
12652
12653
12654
12655
12656
# File 'lib/syntax_tree.rb', line 12651

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



12649
12650
12651
# File 'lib/syntax_tree.rb', line 12649

def comments
  @comments
end

#leftObject (readonly)

GVar

the new alias of the variable



12640
12641
12642
# File 'lib/syntax_tree.rb', line 12640

def left
  @left
end

#locationObject (readonly)

Location

the location of this node



12646
12647
12648
# File 'lib/syntax_tree.rb', line 12646

def location
  @location
end

#rightObject (readonly)

Backref | GVar

the current name of the variable to be aliased



12643
12644
12645
# File 'lib/syntax_tree.rb', line 12643

def right
  @right
end

Instance Method Details

#child_nodesObject



12658
12659
12660
# File 'lib/syntax_tree.rb', line 12658

def child_nodes
  [left, right]
end

#format(q) ⇒ Object



12662
12663
12664
12665
12666
12667
12668
12669
# File 'lib/syntax_tree.rb', line 12662

def format(q)
  keyword = "alias "

  q.text(keyword)
  q.format(left)
  q.text(" ")
  q.format(right)
end

#pretty_print(q) ⇒ Object



12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
# File 'lib/syntax_tree.rb', line 12671

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

    q.breakable
    q.pp(left)

    q.breakable
    q.pp(right)

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

#to_json(*opts) ⇒ Object



12685
12686
12687
12688
12689
12690
12691
12692
12693
# File 'lib/syntax_tree.rb', line 12685

def to_json(*opts)
  {
    type: :var_alias,
    left: left,
    right: right,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end