Class: Rucoa::Definitions::ConstantDefinition

Inherits:
Base
  • Object
show all
Defined in:
lib/rucoa/definitions/constant_definition.rb

Overview

Represents class definition, module definition, or constant assignment.

Direct Known Subclasses

ModuleDefinition

Instance Attribute Summary collapse

Attributes inherited from Base

#description, #location

Instance Method Summary collapse

Constructor Details

#initialize(qualified_name:, **keyword_arguments) ⇒ ConstantDefinition

Returns a new instance of ConstantDefinition.

Parameters:

  • qualified_name (String)


11
12
13
14
15
16
17
# File 'lib/rucoa/definitions/constant_definition.rb', line 11

def initialize(
  qualified_name:,
  **keyword_arguments
)
  super(**keyword_arguments)
  @qualified_name = qualified_name
end

Instance Attribute Details

#qualified_nameString (readonly)

Returns:

  • (String)


8
9
10
# File 'lib/rucoa/definitions/constant_definition.rb', line 8

def qualified_name
  @qualified_name
end

Instance Method Details

#nameString

Examples:

returns non-full-qualified name

definition = Rucoa::Source.new(
  content: <<~RUBY,
    module Foo
      module Bar
        class Baz
        end
      end
    end
  RUBY
  uri: 'file:///path/to/foo/bar/baz.rb',
).definitions[2]
expect(definition.name).to eq('Baz')

Returns:

  • (String)


33
34
35
# File 'lib/rucoa/definitions/constant_definition.rb', line 33

def name
  names.last
end

#namespaceString

Examples:

returns namespace

definition = Rucoa::Source.new(
  content: <<~RUBY,
    module Foo
      module Bar
        class Baz
        end
      end
    end
  RUBY
  uri: 'file:///path/to/foo/bar/baz.rb',
).definitions[2]
expect(definition.namespace).to eq('Foo::Bar')

Returns:

  • (String)


51
52
53
# File 'lib/rucoa/definitions/constant_definition.rb', line 51

def namespace
  names[..-2].join('::')
end