The proper way to do this is outlined here. Since the gemspec is evaluated at package time, you need to do it in a native extension. Don't worry, it's not that scary since its still just Ruby code (not compiling C or anything).
We are currently using this approach for some client tools for OpenShift (source). Then in your gemspec/Rakefile, instead of adding dependencies, you would add an extension. Note that the file needs to be named ext/mkrf_conf.rb
for this to work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…