From: Suraj Kurapati Date: 2010-04-13T09:19:11+09:00 Subject: [ruby-core:29485] [Feature #3131] add Kernel#Hash() method like Kernel#Array() Issue #3131 has been updated by Suraj Kurapati. Hi, Please allow me to clarify. Suraj Kurapati wrote: > Hash::[] does not support conversion from odd-length Array (because > it is uncertain what Ruby must do with the 2n+1'th element) and will > raise an error in such case. I was referring to this particular behavior: >> Hash[1,2,3,4,5,6] => {1=>2, 3=>4, 5=>6} >> Hash[1,2,3,4,5,6,7] ArgumentError: odd number of arguments for Hash from (irb):3:in `[]' from (irb):3 from /usr/bin/irb:12:in `
' I forgot that Hash::[] can convert Array of 2-element Array into Hash: >> Hash[1,2,3,4,[5,6],[7]] # non 2-element Array ignored => {1=>2, 3=>4, [5, 6]=>[7]} >> Hash[[1,2,3,4,[5,6],[7]]] # implicit pair value is nil => {5=>6, 7=>nil} >> Hash[[1,2,3,4,[5,6],[7,8],[7]]] # previous pair is overwritten => {5=>6, 7=>nil} Thanks for your consideration. ---------------------------------------- http://redmine.ruby-lang.org/issues/show/3131 ---------------------------------------- http://redmine.ruby-lang.org