[Rubygems-developers] bug in latest_specs

Ryan Davis ryand-ruby at zenspider.com
Thu Sep 20 04:24:19 EDT 2007


class Gem::SourceIndex
   alias :dead_latest_specs :latest_specs
   def latest_specs
     result, latest = Hash.new { |h,k| h[k] = [] }, {}

     self.each do |_, spec| # SourceIndex is not a hash, so we're  
stuck with each
       name = spec.name
       curr_ver = spec.version
       prev_ver = latest[name]

       next unless prev_ver.nil? or curr_ver >= prev_ver

       if prev_ver.nil? or curr_ver > prev_ver then
         result[name].clear
         latest[name] = curr_ver
       end

       result[name] << spec
     end

     result.values.flatten
   end
end

This is my latest version and works well. I'm using it with flog and  
a new project.


More information about the Rubygems-developers mailing list