Class: Rucoa::Nodes::DefNode

Inherits:
Base
  • Object
show all
Includes:
Rucoa::NodeConcerns::Body, Rucoa::NodeConcerns::Rescue
Defined in:
lib/rucoa/nodes/def_node.rb

Instance Method Summary collapse

Methods included from Rucoa::NodeConcerns::Rescue

#ensure, #rescue

Methods included from Rucoa::NodeConcerns::Body

#body, #body_children

Methods inherited from Base

#ancestors, #child_nodes, #descendant_nodes, #each_ancestor, #each_child_node, #each_descendant_node, #include_position?, #initialize, #module_nesting, #namespace, #next_sibling_nodes, #parent, #parent=, #previous_sibling_nodes, #updated

Constructor Details

This class inherits a constructor from Rucoa::Nodes::Base

Instance Method Details

#argumentsArray<Rucoa::Nodes::ArgNode>

Examples:

returns arguments

node = Rucoa::Source.new(
  content: "    def foo(bar, baz)\n    end\n  RUBY\n  uri: 'file:///path/to/example.rb'\n).root_node\nexpect(node.arguments.map(&:name)).to eq(%w[bar baz])\n",


19
20
21
# File 'lib/rucoa/nodes/def_node.rb', line 19

def arguments
  children[-2]
end

#method_markerString



24
25
26
27
28
29
30
# File 'lib/rucoa/nodes/def_node.rb', line 24

def method_marker
  if singleton?
    '.'
  else
    '#'
  end
end

#nameString

Examples:

returns method name

node = Rucoa::Source.new(
  content: "    module Foo\n      class Bar\n        def baz\n        end\n      end\n    end\n  RUBY\n  uri: 'file:///path/to/foo/bar.rb'\n).node_at(\n  Rucoa::Position.new(\n    column: 4,\n    line: 3\n  )\n)\nexpect(node.name).to eq('baz')\n",


51
52
53
# File 'lib/rucoa/nodes/def_node.rb', line 51

def name
  children[-3].to_s
end

#qualified_nameString

Examples:

returns full qualified name

node = Rucoa::Source.new(
  content: "    module Foo\n      class Bar\n        def baz\n        end\n      end\n    end\n  RUBY\n  uri: 'file:///path/to/foo/bar.rb'\n).node_at(\n  Rucoa::Position.new(\n    column: 4,\n    line: 3\n  )\n)\nexpect(node.qualified_name).to eq('Foo::Bar#baz')\n",


74
75
76
77
78
79
80
# File 'lib/rucoa/nodes/def_node.rb', line 74

def qualified_name
  [
    namespace,
    method_marker,
    name
  ].join
end

#singleton?Boolean



83
84
85
# File 'lib/rucoa/nodes/def_node.rb', line 83

def singleton?
  type == :defs || each_ancestor(:sclass).any?
end