From: Adam Prescott Date: 2012-03-29T23:33:59+09:00 Subject: [ruby-core:43865] Re: [ruby-trunk - Feature #5008] Equal rights for Hash (like Array, String, Integer, Float) --f46d04447f4b335c0004bc629d98 Content-Type: text/plain; charset=UTF-8 On Thu, Mar 29, 2012 at 14:39, Alex Young wrote: > Would you argue that this is wrong and should be removed? > > 1.9.3p125 :001 > nil.to_a > => [] > > If not, why not? > Perhaps I wasn't clear (including to myself). I think nil.to_h is probably fine, for the same reason nil.to_a is fine, and it would nice to have it. But, I think adding #each to NilClass is the wrong way to go to get around being able to call #each on the return value of some method call. If you really need to_h behaviour, I think you can go for || before sticking #each on NilClass. --f46d04447f4b335c0004bc629d98 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Thu, Mar 29, 2012 at 14:39, Alex Young <alex@blackkettle.or= g> wrote:
Would you argue that this is wrong and should be removed?<= br>
1.9.3p125 :001 > nil.to_a
=C2=A0=3D> []

If not, why not?

Perhaps I wasn't clea= r (including to myself).

I think nil.to_h is proba= bly fine, for the same reason nil.to_a is fine, and it would nice to have i= t. But,=C2=A0I think adding #each to NilClass is the wrong way to go to get= around being able to call #each on the return value of some method call. I= f you really need to_h behaviour, I think you can go for || before sticking= #each on NilClass.
--f46d04447f4b335c0004bc629d98--