Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
Gem.try_activate
(::String path) -> bool
try_activate(path)
lib/rubygems.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/rubygems.rb, line 182
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
name = spec.name
spec = Gem::Specification.find_unloaded_by_path(path)
spec ||= Gem::Specification.find_by_name(name)
if spec.nil?
raise e
else
spec.activate
end
end
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.