From: "sawa (Tsuyoshi Sawada)" Date: 2013-12-11T11:22:55+09:00 Subject: [ruby-core:59038] [ruby-trunk - Feature #9239] Array#to_h ignores flat arrays Issue #9239 has been updated by sawa (Tsuyoshi Sawada). marcandre (Marc-Andre Lafortune) wrote: > My opinion is that the fact that `Hash[1,2,3,4] # => {1 => 2, 3 => 4}` is a misfeature and that this usage should not be encouraged. > > On the other hand, Array#to_h could raise an error on elements that are not 2-element arrays. I argued otherwise before, but maybe that would be safer. That is probably the right move. ---------------------------------------- Feature #9239: Array#to_h ignores flat arrays https://bugs.ruby-lang.org/issues/9239#change-43592 Author: sawa (Tsuyoshi Sawada) Status: Open Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: Target version: =begin My understanding was that the newly introduced `Array#to_h` was to be equivalent to `Hash.[]`. But when I give a flat array, it returns an empty hash: [:a, :b].to_h # => {} [:a].to_h # => {} I expected `{:a => :b}` for the first example, and `ArgumentError: odd number of arguments for Hash` for the second example, as is with `Hash[]`. Was it intended to be different? If so, why is that the case? Even if it is to be different, it should at least raise an error when a flat array is given. =end -- http://bugs.ruby-lang.org/