Project

General

Profile

Actions

Feature #9239

closed

Array#to_h ignores flat arrays

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

Status:
Rejected
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 1 (0 open1 closed)

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0