Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

1.8.7: Hash#hash and Hash#eql? are not specialized in Ruby 1.8.6! Fix…

… that (except for recursive structures)
  • Loading branch information...
commit 10ba02021751e2eb6ce671fd558a9acea9037ade 1 parent ce255d3
@marcandre authored
Showing with 21 additions and 3 deletions.
  1. +1 −1  VERSION.yml
  2. +2 −2 backports.gemspec
  3. +18 −0 lib/backports/1.8.7/hash.rb
View
2  VERSION.yml
@@ -1,5 +1,5 @@
---
:major: 1
:minor: 13
-:patch: 0
+:patch: 1
:build:
View
4 backports.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{backports}
- s.version = "1.13.0"
+ s.version = "1.13.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Marc-Andr\303\251 Lafortune"]
- s.date = %q{2010-01-20}
+ s.date = %q{2010-01-22}
s.description = %q{ Essential backports that enable some of the really nice features of ruby 1.8.7, ruby 1.9 and rails from ruby 1.8.6 and earlier.
}
s.email = %q{github@marc-andre.ca}
View
18 lib/backports/1.8.7/hash.rb
@@ -18,6 +18,24 @@ def [](*args)
end
end
+ # Ruby 1.8.6 doesn't define a Hash specific hash method
+ def hash
+ h = 0
+ each do |key, value|
+ h ^= key.hash ^ value.hash
+ end
+ h
+ end unless {}.hash == {}.hash
+
+ # Ruby 1.8.6 doesn't define a Hash specific eql? method.
+ def eql?(other)
+ other.is_a?(Hash) &&
+ size == other.size &&
+ all? do |key, value|
+ other.fetch(key){return false}.eql?(value)
+ end
+ end unless {}.eql?({})
+
Backports.make_block_optional self, :delete_if, :each, :each_key, :each_pair, :each_value, :reject, :reject!, :select, :test_on => {:hello => "world!"}
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Hash.html]

1 comment on commit 10ba020

@marcandre
Owner

Oups, forgot to thank Dan Kubb for pointing this out!

Please sign in to comment.
Something went wrong with that request. Please try again.