Class: RubyModKit::Node::DefNode

Inherits:
BaseNode
  • Object
show all
Defined in:
lib/ruby_mod_kit/node/def_node.rb

Overview

Transpiler program node

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseNode

#ancestors, #children, #def_node_at, #def_parent_node_at, #end_offset, #include?, #inspect, #location, #node_at, #offset, #parameter_node_at, #slice, #statements_node_at

Constructor Details

#initialize(prism_node, parent:, prev: nil) ⇒ void

Parameters:

Raises:

rbs:

  • prism_node: Prism::DefNode

  • parent: Node::BaseNode

  • prev: Node::BaseNode | nil

  • return: void



26
27
28
29
30
31
32
33
# File 'lib/ruby_mod_kit/node/def_node.rb', line 26

def initialize(prism_node, parent:, prev: nil)
  @prism_node = prism_node
  @parent = parent
  @prev = prev
  raise RubyModKit::Error unless prism_node.is_a?(Prism::DefNode)

  super()
end

Instance Attribute Details

#parentObject (readonly)

: Node::BaseNode



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

def parent
  @parent
end

#prevObject (readonly)

: Node::BaseNode | nil



16
17
18
# File 'lib/ruby_mod_kit/node/def_node.rb', line 16

def prev
  @prev
end

Instance Method Details

#body_locationPrism::Location?

Returns:

  • (Prism::Location, nil)

rbs:

  • return: Prism::Location | nil



43
44
45
# File 'lib/ruby_mod_kit/node/def_node.rb', line 43

def body_location
  prism_node.body&.location
end

#body_nodeNode::StatementsNode, ...

Returns:

rbs:

  • return: Node::StatementsNode | Node::BeginNode | nil



90
91
92
93
94
# File 'lib/ruby_mod_kit/node/def_node.rb', line 90

def body_node
  # body_node will be set in #children
  children
  @body_node
end

#end_keyword_locPrism::Location?

Returns:

  • (Prism::Location, nil)

rbs:

  • return: Prism::Location | nil



67
68
69
# File 'lib/ruby_mod_kit/node/def_node.rb', line 67

def end_keyword_loc
  @prism_node.end_keyword_loc
end

#lparen_locPrism::Location?

Returns:

  • (Prism::Location, nil)

rbs:

  • return: Prism::Location | nil



49
50
51
# File 'lib/ruby_mod_kit/node/def_node.rb', line 49

def lparen_loc
  @prism_node.lparen_loc
end

#nameSymbol

Returns:

  • (Symbol)

rbs:

  • return: Symbol



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

def name
  @prism_node.name
end

#name_locPrism::Location

Returns:

  • (Prism::Location)

rbs:

  • return: Prism::Location



61
62
63
# File 'lib/ruby_mod_kit/node/def_node.rb', line 61

def name_loc
  @prism_node.name_loc
end

#rparen_locPrism::Location?

Returns:

  • (Prism::Location, nil)

rbs:

  • return: Prism::Location | nil



55
56
57
# File 'lib/ruby_mod_kit/node/def_node.rb', line 55

def rparen_loc
  @prism_node.rparen_loc
end

#wrap(prism_child_node, prev: nil) ⇒ Node::BaseNode

Parameters:

  • prism_child_node (Prism::Node)
  • prev (Node::BaseNode, nil) (defaults to: nil)

Returns:

rbs:

  • prism_child_node: Prism::Node

  • prev: Node::BaseNode | nil

  • return: Node::BaseNode



77
78
79
80
81
82
83
84
85
86
# File 'lib/ruby_mod_kit/node/def_node.rb', line 77

def wrap(prism_child_node, prev: nil)
  child_node = super
  if prism_child_node == @prism_node.body
    case child_node
    when Node::StatementsNode, Node::BeginNode
      @body_node = child_node
    end
  end
  child_node
end