End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Gem.try_activate
try_activate(path)
lib/rubygems.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/rubygems.rb, line 193
def self.try_activate(path)
# finds the _latest_ version... regardless of loaded specs and their deps
# if another gem had a requirement that would mean we shouldn't
# activate the latest version, then either it would already be activated
# or if it was ambiguous (and thus unresolved) the code in our custom
# require will try to activate the more specific version.
spec = Gem::Specification.find_by_path path
return false unless spec
return true if spec.activated?
begin
spec.activate
rescue Gem::LoadError => e # this could fail due to gem dep collisions, go lax
spec_by_name = Gem::Specification.find_by_name(spec.name)
if spec_by_name.nil?
raise e
else
spec_by_name.activate
end
end
return true
end
Try to activate a gem containing path. Returns true if activation succeeded or wasn’t needed because it was already activated. Returns false if it can’t find the path in a gem.