summary refs log tree commit
path: root/lib/rack/session/abstract/id.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rack/session/abstract/id.rb')
-rw-r--r--lib/rack/session/abstract/id.rb26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/rack/session/abstract/id.rb b/lib/rack/session/abstract/id.rb
index c9f9f458..b15ee3b8 100644
--- a/lib/rack/session/abstract/id.rb
+++ b/lib/rack/session/abstract/id.rb
@@ -17,6 +17,26 @@ module Rack
       # SessionHash is responsible to lazily load the session from store.
 
       class SessionHash
+        using Module.new {
+          refine Hash do
+            def transform_keys(&block)
+              hash = {}
+              each do |key, value|
+                hash[block.call(key)] = value
+              end
+              hash
+            end
+          end
+        } unless {}.respond_to?(:transform_keys)
+
+        def transform_keys(&block)
+          hash = dup
+          each do |key, value|
+            hash[block.call(key)] = value
+          end
+          hash
+        end
+
         include Enumerable
         attr_writer :id
 
@@ -162,11 +182,7 @@ module Rack
         end
 
         def stringify_keys(other)
-          hash = {}
-          other.each do |key, value|
-            hash[key.to_s] = value
-          end
-          hash
+          other.transform_keys(&:to_s)
         end
       end