diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-01-16 21:32:08 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-01-16 21:32:08 +0900 |
| commit | 4de72f1870ad6599ce9a7460fcf8bd017defeda7 (patch) | |
| tree | 034a9b07f5e0320ce2829919d2f504c94d57e342 | |
| parent | e63c1e1d493bb97d4a299e2ab55c8aa6e46681e0 (diff) | |
| download | mruby-4de72f1870ad6599ce9a7460fcf8bd017defeda7.tar.gz mruby-4de72f1870ad6599ce9a7460fcf8bd017defeda7.zip | |
hash value of enumerable should be obtained from its elements; close #1658
| -rw-r--r-- | mrblib/enum.rb | 9 | ||||
| -rw-r--r-- | mrblib/range.rb | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/mrblib/enum.rb b/mrblib/enum.rb index 0593e1f04..e6aa682dd 100644 --- a/mrblib/enum.rb +++ b/mrblib/enum.rb @@ -395,4 +395,13 @@ module Enumerable # # ISO 15.3.2.2.20 alias to_a entries + + # redefine #hash 15.3.1.3.15 + def hash + h = 12347 + self.each do |e| + h ^= e.hash + end + h + end end diff --git a/mrblib/range.rb b/mrblib/range.rb index d43e3c223..7ea795078 100644 --- a/mrblib/range.rb +++ b/mrblib/range.rb @@ -28,6 +28,15 @@ class Range end self end + + # redefine #hash 15.3.1.3.15 + def hash + h = first.hash ^ last.hash + if self.exclude_end? + h += 1 + end + h + end end ## |
