Skip to content

Instantly share code, notes, and snippets.

@tow8ie
Created May 3, 2011 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tow8ie/953254 to your computer and use it in GitHub Desktop.
Save tow8ie/953254 to your computer and use it in GitHub Desktop.
Rack Nested Params Parsing Quiz
# See https://github.com/rack/rack/blob/master/test/spec_utils.rb
# and http://www.ruby-forum.com/topic/215584
# for further details and historical explanation
"x[y][z]=1" # => {"x" => {"y" => {"z" => "1"}}}
"x[y][z][]=1" # => {"x" => {"y" => {"z" => ["1"]}}}
"x[y][z]=1&x[y][z]=2" # => {"x" => {"y" => {"z" => "2"}}}
"x[y][z][]=1&x[y][z][]=2" # => {"x" => {"y" => {"z" => ["1", "2"]}}}
"x[y][][z]=1" # => {"x" => {"y" => [{"z" => "1"}]}}
"x[y][][z][]=1" # => {"x" => {"y" => [{"z" => ["1"]}]}}
"x[y][][z]=1&x[y][][w]=2" # => {"x" => {"y" => [{"z" => "1", "w" => "2"}]}}
"x[y][][v][w]=1" # => {"x" => {"y" => [{"v" => {"w" => "1"}}]}}
"x[y][][z]=1&x[y][][v][w]=2" # => {"x" => {"y" => [{"z" => "1", "v" => {"w" => "2"}}]}}
"x[y][][z]=1&x[y][][z]=2" # => {"x" => {"y" => [{"z" => "1"}, {"z" => "2"}]}}
"x[y][][z]=1&x[y][][w]=a&x[y][][z]=2&x[y][][w]=3" # => {"x" => {"y" => [{"z" => "1", "w" => "a"}, {"z" => "2", "w" => "3"}]}}
"x[y][z]=1" # => {"x" => {"y" => {"z" => "1"}}}
"x[y][z][]=1" # =>
"x[y][z]=1&x[y][z]=2" # =>
"x[y][z][]=1&x[y][z][]=2" # =>
"x[y][][z]=1" # =>
"x[y][][z][]=1" # =>
"x[y][][z]=1&x[y][][w]=2" # =>
"x[y][][v][w]=1" # =>
"x[y][][z]=1&x[y][][v][w]=2" # =>
"x[y][][z]=1&x[y][][z]=2" # =>
"x[y][][z]=1&x[y][][w]=a&x[y][][z]=2&x[y][][w]=3" # =>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment