Skip to content

Instantly share code, notes, and snippets.

@thbishop
Created October 23, 2010 06:33
Show Gist options
  • Save thbishop/641873 to your computer and use it in GitHub Desktop.
Save thbishop/641873 to your computer and use it in GitHub Desktop.
in rubygem package provider
def with_gem_sources(*sources)
sources.compact!
original_sources = Gem.sources
# Gem.sources = sources unless sources.empty?
unless sources.empty?
if Gem.respond_to?(:sources=)
Gem.sources = sources
else
Gem.instance_variable_set(:@sources, sources)
end
end
yield
ensure
if Gem.respond_to?(:sources=)
Gem.sources = sources
else
Gem.instance_variable_set(:@sources, sources)
end
end
# this method doesn't exist in v 1.2.0 of the Gem module, but does in 1.3.7 (haven't checked what version it was introduced yet)
def self.sources=(new_sources)
@sources = new_sources
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment