Class: YARP::AliasNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents the use of the ‘alias` keyword.

alias foo bar
^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_name, old_name, keyword_loc, location) ⇒ AliasNode

def initialize: (new_name: Node, old_name: Node, keyword_loc: Location, location: Location) -> void



24
25
26
27
28
29
# File 'lib/yarp/node.rb', line 24

def initialize(new_name, old_name, keyword_loc, location)
  @new_name = new_name
  @old_name = old_name
  @keyword_loc = keyword_loc
  @location = location
end

Instance Attribute Details

#keyword_locObject (readonly)

attr_reader keyword_loc: Location



21
22
23
# File 'lib/yarp/node.rb', line 21

def keyword_loc
  @keyword_loc
end

#new_nameObject (readonly)

attr_reader new_name: Node



15
16
17
# File 'lib/yarp/node.rb', line 15

def new_name
  @new_name
end

#old_nameObject (readonly)

attr_reader old_name: Node



18
19
20
# File 'lib/yarp/node.rb', line 18

def old_name
  @old_name
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



32
33
34
# File 'lib/yarp/node.rb', line 32

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



37
38
39
# File 'lib/yarp/node.rb', line 37

def child_nodes
  [new_name, old_name]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



42
43
44
# File 'lib/yarp/node.rb', line 42

def comment_targets
  [new_name, old_name, keyword_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> AliasNode



47
48
49
50
51
52
53
54
# File 'lib/yarp/node.rb', line 47

def copy(**params)
  AliasNode.new(
    params.fetch(:new_name) { new_name },
    params.fetch(:old_name) { old_name },
    params.fetch(:keyword_loc) { keyword_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



60
61
62
# File 'lib/yarp/node.rb', line 60

def deconstruct_keys(keys)
  { new_name: new_name, old_name: old_name, keyword_loc: keyword_loc, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/yarp/node.rb', line 69

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── new_name:\n"
  inspector << inspector.child_node(new_name, "")
  inspector << "├── old_name:\n"
  inspector << inspector.child_node(old_name, "")
  inspector << "└── keyword_loc: #{inspector.location(keyword_loc)}\n"
  inspector.to_str
end

#keywordObject

def keyword: () -> String



65
66
67
# File 'lib/yarp/node.rb', line 65

def keyword
  keyword_loc.slice
end