From: Idan Sofer Date: 2003-02-04T22:27:00+09:00 Subject: Re: Mismatch between documenation and implementation of Array#join() Robert Klemme wrote: >Hi, > >I'm wondering whether Array#join() has an error or the documentation is >wrong. Documentation says: >"Returns a string created by converting each element of the array to a >string, separated by aSepString." This apparently does not include >flatten(). But the behavior seems to be like flatten() was invoked before: > >With Ruby version 1.6.7: > >irb(main):015:0* a=[[0,1],[22,33]] >[[0, 1], [22, 33]] >irb(main):016:0> a.join(";") >"0;1;22;33" > > >I would have expected a.join(";") to have returned "01;2233" instead. > I seem to think it is the correct behaviour, Array#join is just invoked in each of the subarrays as well(Recursive behaviour, just as #to_s calls #to_s on all of the array members), however, your wish might be fulfilled this way: a.map { |x| x.to_s }.join(';') or: class Array def join_s(sep=nil) map {|x| x.to_s}.join(sep) end end a.join_s Idan.