Class: Rucoa::Nodes::ClassNode

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

Instance Method Summary collapse

Methods included from Rucoa::NodeConcerns::QualifiedName

#qualified_name

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

#nameString

Returns:

  • (String)


10
11
12
# File 'lib/rucoa/nodes/class_node.rb', line 10

def name
  const_node.name
end

#super_class_chained_nameString?

Examples:

returns nil for class for ‘class Foo`

node = Rucoa::Source.new(
  content: <<~RUBY,
    class Foo
    end
  RUBY
  uri: 'file:///path/to/foo.rb'
).root_node
expect(node.super_class_chained_name).to be_nil

returns “Bar” for class for ‘class Foo < Bar`

node = Rucoa::Source.new(
  content: <<~RUBY,
    class Foo < Bar
    end
  RUBY
  uri: 'file:///path/to/foo.rb'
).root_node
expect(node.super_class_chained_name).to eq('Bar')

returns “Bar::Baz” for class for ‘class Foo < Bar::Baz`

node = Rucoa::Source.new(
  content: <<~RUBY,
    class Foo < Bar::Baz
    end
  RUBY
  uri: 'file:///path/to/foo.rb'
).root_node
expect(node.super_class_chained_name).to eq('Bar::Baz')

returns “::Bar” for class for ‘class Foo < ::Bar`

node = Rucoa::Source.new(
  content: <<~RUBY,
    class Foo < ::Bar
    end
  RUBY
  uri: 'file:///path/to/foo.rb'
).root_node
expect(node.super_class_chained_name).to eq('::Bar')

Returns:

  • (String, nil)


51
52
53
54
55
# File 'lib/rucoa/nodes/class_node.rb', line 51

def super_class_chained_name
  return unless super_class_node.is_a?(Nodes::ConstNode)

  super_class_node.chained_name
end