Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
Gem.register_default_spec
(::Gem::Specification spec) -> ::Array[::String]
register_default_spec(spec)
lib/rubygems.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/rubygems.rb, line 1312
def register_default_spec(spec)
extended_require_paths = spec.require_paths.map {|f| f + "/" }
new_format = extended_require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }
if new_format
prefix_group = extended_require_paths.join("|")
prefix_pattern = /^(#{prefix_group})/
end
native_extension_suffixes = Gem.dynamic_library_suffixes.reject(&:empty?)
spec.files.each do |file|
if new_format
file = file.sub(prefix_pattern, "")
unless $~
# Also register native extension files (e.g. date_core.bundle)
# that are listed without require path prefix in the gemspec
next if file.include?("/")
next unless file.end_with?(*native_extension_suffixes)
end
end
# RubyGems owns this namespace. Bundler lists copies of some of these
# files, and mapping them here would make requiring RubyGems' own file
# activate the default Bundler.
next if file.start_with?("rubygems/")
spec.activate if already_loaded?(file)
@path_to_default_spec_map[file] = spec
@path_to_default_spec_map[file.sub(suffix_regexp, "")] = spec
end
end
Register a Gem::Specification for default gem.
Two formats for the specification are supported:
-
MRI 2.0 style, where spec.files contains unprefixed require names. The spec’s filenames will be registered as-is.
-
New style, where spec.files contains files prefixed with paths from spec.require_paths. The prefixes are stripped before registering the spec’s filenames. Unprefixed files are omitted.