Rubygems does not provide a proper way to specify different dependencies for different ruby ββversions. If we put a conditional expression in gemspec, it can switch what is set:
if RUBY_VERSION < "1.9"
s.runtime_dependency "nokogiri", ">= 1.4.0", "< 1.6"
else
s.runtime_dependency "nokogiri", ">= 1.4.0"
end
But this does not control the download. If there is a newer version in the download path that will load, even if it is not compatible with ruby ββ1.8.
I'm not sure if this is really a problem: if you use rbenv / rvm, etc., you have different ways to create gems for each ruby, so I hope you never installed them in one place. I think that even the standard gem paths are separated by compatibility versions (1.8 / 1.9.1). Is this meant to take care of this, or could you ever get into a situation where both versions are installed together?
Another approach is to leave gemspec open (without conditional) and warn users to set the correct version limit in their Gemfile if it needs it.
Which method is preferable?
source
share