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.



12116
12117
12118
12119
12120
12121
# File 'lib/syntax_tree.rb', line 12116

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



12114
12115
12116
# File 'lib/syntax_tree.rb', line 12114

def comments
  @comments
end

#leftObject (readonly)

GVar

the new alias of the variable



12105
12106
12107
# File 'lib/syntax_tree.rb', line 12105

def left
  @left
end

#locationObject (readonly)

Location

the location of this node



12111
12112
12113
# File 'lib/syntax_tree.rb', line 12111

def location
  @location
end

#rightObject (readonly)

Backref | GVar

the current name of the variable to be aliased



12108
12109
12110
# File 'lib/syntax_tree.rb', line 12108

def right
  @right
end

Instance Method Details

#child_nodesObject



12123
12124
12125
# File 'lib/syntax_tree.rb', line 12123

def child_nodes
  [left, right]
end

#format(q) ⇒ Object



12127
12128
12129
12130
12131
12132
12133
12134
# File 'lib/syntax_tree.rb', line 12127

def format(q)
  keyword = "alias "

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

#pretty_print(q) ⇒ Object



12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
# File 'lib/syntax_tree.rb', line 12136

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



12150
12151
12152
12153
12154
12155
12156
12157
12158
# File 'lib/syntax_tree.rb', line 12150

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