Jan
26

Is this gem installed?

Ever find yourself deep in some code, wishing that you could figure out if a gem was installed, without trying to call against it and deal with the ensuing nastyness? Here’s how:

dependency = Gem::Dependency.new "authlogic", ">2"
specs = Gem.source_index.search dependency
puts "the gem is not installed" if specs.empty?

Thanks to rubygems-sing for the simple implementation.

Share and Enjoy:
  • Twitter
  • Digg
  • del.icio.us
  • Google Bookmarks
  • Facebook
  • E-mail this story to a friend!
  • Print this article!
  • Posterous