method
try_activate
ruby latest stable - Class:
Gem
try_activate(path)public
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.
# File lib/rubygems.rb, line 206
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 Related methods
- Class methods
- activate_bin_path
- bin_path
- binary_mode
- bindir
- clear_default_specs
- clear_paths
- config_file
- configuration
- configuration=
- datadir
- default_bindir
- default_cert_path
- default_dir
- default_exec_format
- default_ext_dir_for
- default_gems_use_full_paths?
- default_key_path
- default_path
- default_rubygems_dirs
- default_sources
- default_spec_cache_dir
- deflate
- detect_gemdeps
- dir
- done_installing
- ensure_default_gem_subdirectories
- ensure_gem_subdirectories
- ensure_subdirectories
- env_requirement
- extension_api_version
- find_files
- find_files_from_load_path
- find_latest_files
- find_unresolved_default_spec
- finish_resolve
- gunzip
- gzip
- host
- host=
- inflate
- install
- install_extension_in_lib
- latest_rubygems_version
- latest_spec_for
- latest_version_for
- load_env_plugins
- load_path_insert_index
- load_plugin_files
- load_plugins
- load_yaml
- location_of_caller
- marshal_version
- needs
- path
- path_separator
- paths
- paths=
- platform_defaults
- platforms
- platforms=
- post_build
- post_install
- post_reset
- post_uninstall
- pre_install
- pre_reset
- pre_uninstall
- prefix
- read_binary
- refresh
- register_default_spec
- remove_unresolved_default_spec
- ruby
- ruby=
- ruby_api_version
- ruby_engine
- ruby_version
- rubygems_version
- searcher=
- sources
- sources=
- spec_cache_dir
- suffix_pattern
- suffixes
- time
- try_activate
- ui
- use_gemdeps
- use_paths
- user_dir
- user_home
- vendor_dir
- win_platform=
- win_platform?
- write_binary
- Private methods
-
find_home -
find_spec_for_exe