summaryrefslogtreecommitdiff
path: root/ext/digest/lib/digest.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/digest/lib/digest.rb')
-rw-r--r--ext/digest/lib/digest.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/ext/digest/lib/digest.rb b/ext/digest/lib/digest.rb
index ba0637af32..e995adb450 100644
--- a/ext/digest/lib/digest.rb
+++ b/ext/digest/lib/digest.rb
@@ -1,5 +1,19 @@
# frozen_string_literal: false
-require 'digest.so'
+
+if defined?(Digest) &&
+ /\A(?:2\.|3\.0\.[0-2]\z)/.match?(RUBY_VERSION) &&
+ caller_locations.any? { |l|
+ %r{/(rubygems/gem_runner|bundler/cli)\.rb}.match?(l.path)
+ }
+ # Before Ruby 3.0.3/3.1.0, the gem and bundle commands used to load
+ # the digest library before loading additionally installed gems, so
+ # you will get constant redefinition warnings and unexpected
+ # implementation overwriting if we proceed here. Avoid that.
+ return
+end
+
+require 'digest/version'
+require 'digest/loader'
module Digest
# A mutex for Digest().
@@ -8,7 +22,7 @@ module Digest
def self.const_missing(name) # :nodoc:
case name
when :SHA256, :SHA384, :SHA512
- lib = 'digest/sha2.so'
+ lib = 'digest/sha2'
else
lib = File.join('digest', name.to_s.downcase)
end