diff options
author | Rafael França <rafael@franca.dev> | 2019-10-09 13:52:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-09 13:52:12 -0400 |
commit | 76cfc9087568a75038c23cf2a0b9893563690a05 (patch) | |
tree | 35668c3c2003fadd7f8182495c3a46734433be36 | |
parent | 2512b5455f8049a463e48786fbb9fdf474324345 (diff) | |
parent | 152a75da69aa613527ea02baff9a38a8a902a2f3 (diff) | |
download | rack-76cfc9087568a75038c23cf2a0b9893563690a05.tar.gz |
Merge pull request #1391 from styd/use-transform-keys-to-stringify-keys
Make stringify_keys use transform_keys
-rw-r--r-- | lib/rack/session/abstract/id.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/rack/session/abstract/id.rb b/lib/rack/session/abstract/id.rb index c9f9f458..c9258644 100644 --- a/lib/rack/session/abstract/id.rb +++ b/lib/rack/session/abstract/id.rb @@ -17,6 +17,18 @@ 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) + include Enumerable attr_writer :id @@ -162,11 +174,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 |