Created
May 1, 2009 15:42
-
-
Save TwP/105098 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Kernel | |
# Settiing this global variable to +false+ will disable rubygems from | |
# being loaded at all. | |
$use_rubygems = true | |
# call-seq: | |
# require!( string ) | |
# require!( string, gem_version ) | |
# require!( string, gem_name, gem_version ) | |
# | |
# Attempt to the load the library named _string_ using the standard | |
# Kernel#require method. If the library cannot be loaded then require | |
# rubygems and retry the original require of the library. | |
# | |
# Raises a LoadError if the library cannot be loaded. | |
# | |
# If a _gem_version_ is given, then the rubygems +gem+ command is used to | |
# load the specific version of the gem. The library _string_ is used for | |
# the _gem_name_ if one is omitted. | |
# | |
def require!( string, *args ) | |
return require(string) if args.empty? | |
name, version = *args | |
version, name = name, string if name =~ %r/^[0-9<>=~]/ | |
gem name, version | |
require(string) | |
rescue LoadError, NoMethodError | |
retry if $use_rubygems and require('rubygems') | |
raise | |
end | |
# call-seq: | |
# require?( string ) | |
# require?( string, gem_version ) | |
# require?( string, gem_name, gem_version ) | |
# | |
# Attempt to the load the library named _string_ using the standard | |
# Kernel#require method. If the library cannot be loaded then require | |
# rubygems and retry the original require of the library. | |
# | |
# Returns +true+ if the library was successfully loaded. Returns +false+ | |
# if the library could not be loaded. This method will never raise an | |
# exception. | |
# | |
# If a _gem_version_ is given, then the rubygems +gem+ command is used to | |
# load the specific version of the gem. The library _string_ is used for | |
# the _gem_name_ if one is omitted. | |
# | |
def require?( string, *args ) | |
require!(string, *args) | |
return true | |
rescue LoadError | |
return false | |
end | |
end # module Kernel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment