Skip to content

Commit

Permalink
1.8.7: Hash#hash and Hash#eql? are not specialized in Ruby 1.8.6! Fix…
Browse files Browse the repository at this point in the history
… that (except for recursive structures)
  • Loading branch information
marcandre committed Jan 22, 2010
1 parent ce255d3 commit 10ba020
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION.yml
@@ -1,5 +1,5 @@
---
:major: 1
:minor: 13
:patch: 0
:patch: 1
:build:
4 changes: 2 additions & 2 deletions backports.gemspec
Expand Up @@ -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}
Expand Down
18 changes: 18 additions & 0 deletions lib/backports/1.8.7/hash.rb
Expand Up @@ -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]
Expand Down

1 comment on commit 10ba020

@marcandre
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.