summaryrefslogtreecommitdiffhomepage
path: root/mrblib/hash.rb
diff options
context:
space:
mode:
Diffstat (limited to 'mrblib/hash.rb')
-rw-r--r--mrblib/hash.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/mrblib/hash.rb b/mrblib/hash.rb
index cb52c1ffe..48ac96e56 100644
--- a/mrblib/hash.rb
+++ b/mrblib/hash.rb
@@ -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