From: "marcandre (Marc-Andre Lafortune)" Date: 2013-12-21T02:59:28+09:00 Subject: [ruby-core:59235] [ruby-trunk - Feature #9270][Open] Array#to_h should not ignore badly formed elements Issue #9270 has been reported by marcandre (Marc-Andre Lafortune). ---------------------------------------- Feature #9270: Array#to_h should not ignore badly formed elements https://bugs.ruby-lang.org/issues/9270 Author: marcandre (Marc-Andre Lafortune) Status: Open Priority: Urgent Assignee: naruse (Yui NARUSE) Category: core Target version: current: 2.1.0 The upcoming Array#to_h feature currently ignores elements that are not 2-elements arrays. Array#to_h could instead raise an error on those elements. I argued otherwise before, but maybe that would be safer. One reason I think I was wrong is that current form could encourage code like: enum.map{|x| [x.foo, x.bar] if x.baz? }.to_h using the fact that any `nil` will be ignored. I'm not sure that it's a good idea. It would probably be safer to raise an Exception for elements that are not a key-value pair. It also satisfies fail-early principle. @sawa agrees with this. @matz agrees with the change. Since this feature has not already been released in an official version, changing this behavior now would not cause any incompatibility and there should be no risk of regression. Changing this feature after the official 2.1 release would be more problematic as it could cause incompatibilities. Yui, could you please confirm that there is no problem on your end for me to commit the following patch: https://github.com/marcandre/ruby/compare/to_h_raise -- http://bugs.ruby-lang.org/