From: Jeremy Kemper Date: 2010-03-04T02:46:51+09:00 Subject: [ruby-core:28449] Re: [Bug #1893] Recursive Enumerable#join is surprising --0016363104171b6f790480e91190 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Mar 3, 2010 at 12:14 AM, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: [ruby-core:28422] [Bug #1893] Recursive Enumerable#join is > surprising" > on Wed, 3 Mar 2010 00:57:26 +0900, Yusuke Endoh > writes: > > |I guess adding Enumerator#to_ary is a right solution. > > I don't think so, supplying to_ary means that object can be considered > as an array, which is not always the case. > > matz. > Argh, right. Perhaps an #as_ary, or #as_array, to indicate that the object may coerced to an array. #to_a is too loose for this: it says the object has an array representation. #to_ary is too strict: it says the object may be treated as an array, even without calling the method. #as_ary is in between: it says the object may be treated as an array with coercion, so call the method. This is a similar situation with to_s/to_str and the proposed to_r/to_rat, to_f/to_flo. I think these confusions could be resolved with as_str and as_rat. The fact that many classes incorrectly provide #to_ary is good evidence, too (much like classes that incorrectly provide #to_str). From Benoit's comment: 2 Net::HTTPResponse#to_ary 3 Nokogiri::XML::NodeSet#to_ary 4 Rake::FileList#to_ary 5 WEBrick::HTTPUtils::FormData#to_ary These would be better stated as #as_ary. jeremy --0016363104171b6f790480e91190 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Wed, Mar 3, 2010 at 12:14 AM, Yukihir= o Matsumoto <mat= z@ruby-lang.org> wrote:
Hi,

In message "Re: [ruby-core:28422] [Bug #1893] Recursive Enumerable#joi= n is surprising"
=A0 =A0on Wed, 3 Mar 2010 00:57:26 +0900, Yusuke Endoh &= lt;redmine@ruby-lang.org> w= rites:

|I guess adding Enumerator#to_ary is a right solution.

I don't think so, supplying to_ary means that object can be consi= dered
as an array, which is not always the case.

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0matz.

Argh, right. Perhaps an #as_ary, or #as_array, to indicate that the o= bject may coerced to an array.

#to_a is too loose for this: it says the object has an array representation= .

#to_ary is too strict: it says the object may be= treated as an array, even without calling the method.

#as_ary is in between: it says the object may be treated as an array w= ith coercion, so call the method.

This is a simila= r situation with to_s/to_str and the proposed to_r/to_rat, to_f/to_flo. I t= hink these confusions could be resolved with as_str and as_rat.

The fact that many classes incorrectly provide #to_ary = is good evidence, too (much like classes that incorrectly provide #to_str).= =A0From Benoit's comment:

=A0= =A02 Net::HTTPResponse#to_ary
=A0 3 Nokogiri::XML::NodeSet#to_ary
=A0= 4 Rake::FileList#to_ary
=A0 5 WEBrick::HTTPUtils::FormData#to_ary

T= hese would be better stated as #as_ary.

jeremy
--0016363104171b6f790480e91190--