From: Yusuke ENDOH Date: 2010-03-12T18:17:16+09:00 Subject: [ruby-core:28625] Re: [Bug #1893] Recursive Enumerable#join is surprising Hi, 2010/3/12 Yukihiro Matsumoto : > In message "Re: [ruby-core:28622] Re: [Bug #1893] Recursive Enumerable#join is surprising" > on Fri, 12 Mar 2010 12:25:00 +0900, Yusuke ENDOH writes: > > |2010/3/12 Yukihiro Matsumoto : > |> We should do something: > |> > |> (a) revert and remove Enumerable#join altogether, leaving Array#join. > |> (b) make Enumerable#join not to join recursively; I think Array#join > |> should remain recursive join for array elements. > | > | > |Thank you for remembering the issue! > |But I like: (c) revert it and leave Enumerable#join. > > I am not sure what you mean by (c). - Array#join will not call to_a. - both Array#join and Enumerable#join will remain and recursively join Array (and Enumerator, if possible). > By the way, I should have mentioned that Array#join will not call > #to_a (but #to_ary) either we choose (a) or (b). I see. Good. > |If Enumerator is similar to Array, (c-1) Enumerator#to_ary > |should be defined. > |Otherwise, (c-2) merely Array#join should not call to_a to > |flatten Enumerator. > | > |I still prefer (c-1), though you rejected it once. > > Implicit conversion methods such as #to_ary and #to_str should be > defined only when the object provides (almost) equivalent behavior > (i.e. method set). Enumerable and Array are not the case. When you say two objects are "almost equivalent", do you expect duck typing? If they behave the same enough, we can directly call #each, #[], #[]=, etc. without calling #to_ary. I cannot see the reason why #to_ary is needed if the requirement for defining #to_ary is so rigorous. Is #to_ary just for performance? If so, I think we should handle an array-like object as an array even if it doesn't provide #to_ary. I admit I'm slightly radical, but it is enough for me to think Array and Enumerator "almost equivalent" because both have one sequence of elements with order. Random-access feature is not important for me because "Array" is not already just an "array". It serves as a set, list, queue, assoc list, etc. -- Yusuke ENDOH