Sha256: ed6eb4f563a46631bf4030190bb52f9ef43e3622a38eeae46c06d8806c9ba77d

Contents?: true

Size: 1.6 KB

Versions: 30

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module RBS
  module Prototype
    class Runtime
      module Helpers
        private

        # Returns the exact name & not compactly declared name
        def only_name(mod)
          # No nil check because this method is invoked after checking if the module exists
          const_name!(mod).split(/::/).last or raise # (A::B::C) => C
        end

        def const_name!(const)
          const_name(const) or raise
        end

        def const_name(const)
          @module_name_method ||= Module.instance_method(:name)
          name = @module_name_method.bind(const).call
          return nil unless name

          begin
            deprecated, Warning[:deprecated] = Warning[:deprecated], false
            Object.const_get(name)
          rescue NameError
            # Should generate const name if anonymous or internal module (e.g. NameError::message)
            nil
          else
            name
          ensure
            Warning[:deprecated] = deprecated
          end
        end

        def to_type_name(name, full_name: false)
          *prefix, last = name.split(/::/)

          last or raise

          if full_name
            if prefix.empty?
              TypeName.new(name: last.to_sym, namespace: Namespace.empty)
            else
              TypeName.new(name: last.to_sym, namespace: Namespace.parse(prefix.join("::")))
            end
          else
            TypeName.new(name: last.to_sym, namespace: Namespace.empty)
          end
        end

        def untyped
          @untyped ||= Types::Bases::Any.new(location: nil)
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
rbs-relaxed-3.9.0.1 lib/rbs/prototype/runtime/helpers.rb
rbs-3.8.1 lib/rbs/prototype/runtime/helpers.rb
rbs-3.8.0 lib/rbs/prototype/runtime/helpers.rb
rbs-3.8.0.pre.1 lib/rbs/prototype/runtime/helpers.rb
rbs-3.7.0.pre.1 lib/rbs/prototype/runtime/helpers.rb
rbs-3.7.0.dev.1 lib/rbs/prototype/runtime/helpers.rb
rbs-3.6.1 lib/rbs/prototype/runtime/helpers.rb
rbs-3.6.0 lib/rbs/prototype/runtime/helpers.rb
rbs-3.6.0.pre.3 lib/rbs/prototype/runtime/helpers.rb
rbs-3.6.0.pre.2 lib/rbs/prototype/runtime/helpers.rb
rbs-3.6.0.pre.1 lib/rbs/prototype/runtime/helpers.rb
rbs-3.6.0.dev.1 lib/rbs/prototype/runtime/helpers.rb
rbs-3.5.3 lib/rbs/prototype/runtime/helpers.rb
rbs-3.5.2 lib/rbs/prototype/runtime/helpers.rb
rbs-3.5.1 lib/rbs/prototype/runtime/helpers.rb
rbs-3.5.1.pre.1 lib/rbs/prototype/runtime/helpers.rb
rbs-3.5.0 lib/rbs/prototype/runtime/helpers.rb
rbs-3.5.0.pre.2 lib/rbs/prototype/runtime/helpers.rb
rbs-3.5.0.pre.1 lib/rbs/prototype/runtime/helpers.rb
rbs-3.4.4 lib/rbs/prototype/runtime/helpers.rb