Issue #1893 has been updated by Yusuke Endoh.


Hi Jeremy,

> >> Bar = Struct.new(:a, :b)
> => Bar
> >> bars = [Bar.new('1', '2'), Bar.new('3', '4')]
> => [#<struct Bar a="1", b="2">, #<struct Bar a="3", b="4">]
> >> bars * '--'
> => "1--2--3--4"
> 
> Surprising? It looks like joining Arrays not Structs. Let's define to_s:
> 
> >> class Bar; def to_s; 'foo' end end
> => nil
> >> bars * '--'
> => "1--2--3--4"
> 
> Doesn't work! Strange.

I agree with your intuition.


> There are two solutions:
> * remove Struct#to_a, or

It is too incompatible to be accepted.

> I think we need a to_ary (like to_str) for the recursive array case instead of using to_a.

I think it is reasonable, and Array#flatten actually does so.

But there seems to be a reason why to_a is used.  This behavior
(calling to_a) is introduced because of "recursive join for
Enumerators." (r23951)
Calling to_ary does not meet the rationale because Enumerator
has no #to_ary currently.

I guess adding Enumerator#to_ary is a right solution.

-- 
Yusuke ENDOH <mame / tsg.ne.jp>
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1893

----------------------------------------
http://redmine.ruby-lang.org