From: "matz (Yukihiro Matsumoto)" Date: 2012-07-14T15:12:16+09:00 Subject: [ruby-core:46417] [ruby-trunk - Bug #5406] inconsistent odd-length array rejection in Hash[*ary] vs Hash[ary] Issue #5406 has been updated by matz (Yukihiro Matsumoto). Assignee changed from matz (Yukihiro Matsumoto) to nobu (Nobuyoshi Nakada) Hash[](ary) should raise an exception, when invalid input comes. Matz. ---------------------------------------- Bug #5406: inconsistent odd-length array rejection in Hash[*ary] vs Hash[ary] https://bugs.ruby-lang.org/issues/5406#change-28039 Author: sunaku (Suraj Kurapati) Status: Assigned Priority: Normal Assignee: nobu (Nobuyoshi Nakada) Category: core Target version: 2.0.0 ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux] Hello, Hash[*ary] raises an error when given odd number of arguments: >> Hash.[]( 1, 2, 3 ) ArgumentError: odd number of arguments for Hash from (irb):3:in `[]' from (irb):3 from /usr/bin/irb:12:in `
' In contrast, Hash[ary] silently accepts odd-length arrays: >> Hash.[]( [1, 2, 3] ) {} >> Hash.[]( [[1, 2], 3] ) { 1 => 2 } >> Hash.[]( [[1, 2], [3]] ) { 1 => 2, 3 => nil } >> Hash.[]( [[1, 2], [3,4,5]] ) { 1 => 2 } I think this behavior is inconsistent. Please either: (1) change Hash[ary] to raise errors upon seeing odd-length arrays or (2) change Hash[*ary] to not raise an error for odd number of arguments and instead accept the last odd argument as a key with value nil, just like this existing behavior: >> Hash.[]( [[1, 2], [3]] ) { 1 => 2, 3 => nil } Thanks for your consideration. -- http://bugs.ruby-lang.org/