Project

General

Profile

Feature #9239

Array#to_h ignores flat arrays

Added by sawa (Tsuyoshi Sawada) over 6 years ago. Updated over 6 years ago.

Status:
Rejected
Priority:
Normal
Target version:
[ruby-core:59032]

Description

=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


Related issues

Related to Backport21 - Backport #9270: Array#to_h should not ignore badly formed elementsClosednaruse (Yui NARUSE)12/21/2013Actions

Also available in: Atom PDF