From: matz@... (Yukihiro Matsumoto) Date: 2003-07-20T01:56:08+09:00 Subject: Re: Proposal: Array#to_h, to simplify hash generation Hi, In message "Re: Proposal: Array#to_h, to simplify hash generation" on 03/07/20, Gavin Sinclair writes: |I thought it sounded familiar, but didn't see an RCR. I don't remember the RCR number. Search for "hashify". |What don't you like about #to_h? I just didn't feel we had consensus. Besides, "to_h" you've proposed work for arrays with specific structure (assoc like). |#to_hash is fine by me too, but I don't really know the nuances of |to_s/to_str, to_a/to_ary, ... Longer versions are for implicit conversion. An object that has "to_str" works like a string if it's given as an argument. Note we have "to_hash" already. But this would not be the reason for "to_h". We have "to_io" without the shorter version, for example. |> * what if the original array is not an assoc array (array of arrays |> of two elements). raise error? ignore? | |Raise error. #to_h is clearly a method to be used with care. People |are unlikely to call it on random objects. Of course, [1,2,3,4].to_h |could be the equivalent to Hash[1,2,3,4]. But then there's the corner |case: [ [1,2], "x", [7,8], "g" ].to_h. | |I think I would insist on the input being an assoc array. TypeError? or ArgumentError? I just remembered that I thought Hash[ary] might be the better solution. I'm not sure why I didn't implement it. I have very loose memory. matz.