summaryrefslogtreecommitdiffhomepage
path: root/mrblib/hash.rb
diff options
context:
space:
mode:
Diffstat (limited to 'mrblib/hash.rb')
-rw-r--r--mrblib/hash.rb27
1 files changed, 25 insertions, 2 deletions
diff --git a/mrblib/hash.rb b/mrblib/hash.rb
index e7c51fb1f..48ac96e56 100644
--- a/mrblib/hash.rb
+++ b/mrblib/hash.rb
@@ -10,7 +10,7 @@ class Hash
# hash.
#
# ISO 15.2.13.4.1
- def == (hash)
+ def ==(hash)
return true if self.equal?(hash)
begin
hash = hash.to_hash
@@ -54,7 +54,7 @@ class Hash
#
# ISO 15.2.13.4.8
def delete(key, &block)
- if block && ! self.has_key?(key)
+ if block && !self.has_key?(key)
block.call(key)
else
self.__delete(key)
@@ -319,6 +319,29 @@ class Hash
h
end
+ ##
+ # call-seq:
+ # hsh.rehash -> hsh
+ #
+ # Rebuilds the hash based on the current hash values for each key. If
+ # values of key objects have changed since they were inserted, this
+ # method will reindex <i>hsh</i>.
+ #
+ # h = {"AAA" => "b"}
+ # h.keys[0].chop!
+ # h #=> {"AA"=>"b"}
+ # h["AA"] #=> nil
+ # h.rehash #=> {"AA"=>"b"}
+ # h["AA"] #=> "b"
+ #
+ def rehash
+ h = {}
+ self.each{|k,v|
+ h[k] = v
+ }
+ self.replace(h)
+ end
+
def __update(h)
h.each_key{|k| self[k] = h[k]}
self