forked from rack/rack
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
I was looking around the code and found this piece of code that turns an array into a Hash. The basic idea is to flatten an array to create a list of key, value and then pass it into a Hash[].
https://github.com/codereading/rack/blob/rack-1.4/lib/rack/request.rb#L57
ary = [ [:foo, "bar"], [:fii, "baz"] ].flatten #=> [ :foo, "bar", :fii, "baz"]
Hash[ary] #=> {"foo"=> "bar", "fii"=> "baz"}
Hash[*content_type.split(/\s*[;,]\s*/)[1..-1].
collect { |s| s.split('=', 2) }.
map { |k,v| [k.downcase, v] }.flatten]This may be not a big thing but I brought it on because I've used it a couple of times.
Metadata
Metadata
Assignees
Labels
No labels