From e6edebe4288c98827e723d75fe9fea4c1a0b013f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 18 Nov 2011 22:49:55 +0000 Subject: [PATCH] backend: make url_decode easier to read (for me, at least) I never learned to read Hash[] well. Also, String#freeze on keys to prevent Ruby from calling String#dup for us. --- lib/mogilefs/backend.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb index b754bbc..454685a 100644 --- a/lib/mogilefs/backend.rb +++ b/lib/mogilefs/backend.rb @@ -372,9 +372,12 @@ class MogileFS::Backend # Turns a url params string into a Hash. def url_decode(str) # :nodoc: - Hash[*(str.split(/&/).map! { |pair| - pair.split(/=/, 2).map! { |x| url_unescape(x) } - } ).flatten] + rv = {} + str.split(/&/).each do |pair| + k, v = pair.split(/=/, 2).map! { |x| url_unescape(x) } + rv[k.freeze] = v + end + rv end # :stopdoc: -- 2.11.4.GIT