Class: SyntaxTree::VarAlias

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.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.



10970
10971
10972
10973
10974
10975
# File 'lib/syntax_tree/node.rb', line 10970

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



10968
10969
10970
# File 'lib/syntax_tree/node.rb', line 10968

def comments
  @comments
end

#leftObject (readonly)

GVar

the new alias of the variable



10959
10960
10961
# File 'lib/syntax_tree/node.rb', line 10959

def left
  @left
end

#locationObject (readonly)

Location

the location of this node



10965
10966
10967
# File 'lib/syntax_tree/node.rb', line 10965

def location
  @location
end

#rightObject (readonly)

Backref | GVar

the current name of the variable to be aliased



10962
10963
10964
# File 'lib/syntax_tree/node.rb', line 10962

def right
  @right
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



10977
10978
10979
# File 'lib/syntax_tree/node.rb', line 10977

def child_nodes
  [left, right]
end

#deconstruct_keys(keys) ⇒ Object



10983
10984
10985
# File 'lib/syntax_tree/node.rb', line 10983

def deconstruct_keys(keys)
  { left: left, right: right, location: location, comments: comments }
end

#format(q) ⇒ Object



10987
10988
10989
10990
10991
10992
10993
10994
# File 'lib/syntax_tree/node.rb', line 10987

def format(q)
  keyword = "alias "

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

#pretty_print(q) ⇒ Object



10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
# File 'lib/syntax_tree/node.rb', line 10996

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



11010
11011
11012
11013
11014
11015
11016
11017
11018
# File 'lib/syntax_tree/node.rb', line 11010

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