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]



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

def child_nodes
  [new_name, old_name]
end

#deconstruct_keys(keys) ⇒ Object

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



46
47
48
# File 'lib/yarp/node.rb', line 46

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

#keywordObject

def keyword: () -> String



51
52
53
# File 'lib/yarp/node.rb', line 51

def keyword
  keyword_loc.slice
end