Module: Docscribe::Infer::Names
- Defined in:
- lib/docscribe/infer/names.rb
Overview
Constant-name helpers for turning AST nodes into fully qualified names.
Class Method Summary collapse
-
.build_const_full_name(node) ⇒ String
Build the fully qualified name from a ‘:const` node.
-
.const_full_name(node) ⇒ String?
Convert a ‘:const` / `:cbase` AST node into a fully qualified constant name.
Class Method Details
.build_const_full_name(node) ⇒ String
Note:
module_function: when included, also defines # (instance visibility: private)
Build the fully qualified name from a ‘:const` node.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/docscribe/infer/names.rb', line 38 def build_const_full_name(node) scope, name = *node scope_name = const_full_name(scope) if scope_name && !scope_name.empty? "#{scope_name}::#{name}" elsif scope_name == '' "::#{name}" else name.to_s end end |
.const_full_name(node) ⇒ String?
Note:
module_function: when included, also defines #const_full_name (instance visibility: private)
Convert a ‘:const` / `:cbase` AST node into a fully qualified constant name.
Examples:
-
‘Foo` => `“Foo”`
-
‘Foo::Bar` => `“Foo::Bar”`
-
‘::Foo::Bar` => `“::Foo::Bar”`
Returns nil for unsupported nodes.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/docscribe/infer/names.rb', line 21 def const_full_name(node) return nil unless node.is_a?(Parser::AST::Node) case node.type when :const build_const_full_name(node) when :cbase '' end end |