Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created August 20, 2009 05:22
Show Gist options
  • Save thinkerbot/170855 to your computer and use it in GitHub Desktop.
Save thinkerbot/170855 to your computer and use it in GitHub Desktop.
Array.hash error for Bignum
require 'rubygems'
# Array.hash for objects do not produce a Fixnum hash will blow up. This issue
# will be fixed in a future release but I thought you might like to know in
# case you wanted to patch RubyGems for versions prior to the fix.
#
# (see http://redmine.ruby-lang.org/issues/show/1883)
#
# I found this error because it prevents an array of Gem::Specifications from
# being converted to YAML, as shown below. Note that in the example rack was
# picked because it's common and fails on my box. If for some reason your rack
# succeeds, I found about half my gems will fail, so surely you will have some
# other one that fails too.
begin
# fails
Gem.source_index.find_name("rack").hash
rescue(RangeError)
puts "fail with current hash method: (#{$!.message})"
end
begin
# fails
Gem.source_index.find_name("rack").to_yaml
rescue(RangeError)
puts "fail with current hash method: (#{$!.message})"
end
class Gem::Specification
def hash
# one way to produce a Fixnum hash
super.hash
end
end
# success
Gem.source_index.find_name("rack").hash
Gem.source_index.find_name("rack").to_yaml
puts "new hash method is ok"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment