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
Sep
29

Testing the Halting Problem

I wrote a piece of code recently to follow a linked list. We were linking records together in a way that a few records would normally be grouped together in a tree, with one parent above them all. However, because of the way the records were linked, it was also possible for a loop to occur — that is A would reference B, B would reference C, and C would reference A.

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