Hi --

On Mon, 20 Jul 2009, NARUSE, Yui wrote:

> This seems spec.
>
> When the number of argument for Hash[] is 1,
> the argument must be a hash (or hash like object) or an array (or array like).
>
> And the array object must be an array of two or one length array.
> Your code is an array of integer, so the code returns the empty hash.

I'm not sure I understand the reasoning behind that. It seems awfully
complicated and hard to follow:

>> Hash[]
=> {}
>> Hash[1]
ArgumentError: odd number of arguments for Hash
>> Hash[1,2]
=> {1=>2}
>> Hash[[1,2]]
=> {}
>> Hash[[[1,2]]]
=> {1=>2}

I'm not clear on the underlying design principle, I guess. The 1.8
version seems like it was easier to read; an odd number of arguments
was wrong, which makes sense (to me) for a hash.

Wouldn't it be clearer if Hash[[1,2]] was an error?


David

-- 
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (http://manning.com/black2)
Training! Intro to Ruby, with Black & Kastner, September 14-17
(More info: http://rubyurl.com/vmzN)