From: Len Lawrence Date: 2009-06-14T02:20:07+09:00 Subject: Re: Last element skip in array mapping On Sat, 13 Jun 2009 09:52:17 -0700, Matt Neuburg wrote: > Len Lawrence wrote: > >> Still a newbie after 2 years, investigating obscure corners of the >> language (version 1.8). I made some tests based on a discussion in >> _why's "bits" RedHanded blog: >> >> a = [ 1, 2, 3, 4, 5, nil ] >> b = [ 1, 2, 3, 4, 5 ] >> x = a.map { |k| k.to_s }.join( "0\n" ) puts x >> >> s = a.map { |k| k }.join( "0\n" ) >> puts s >> >> z = a.to_a.join( "00\n" ) >> puts z >> >> beep = b * "000\n" >> puts beep >> >> Unless the dummy element is added to the array (as in a) the series >> does not complete for any of the mapping methods. Am I missing >> something here? > > Consider: > > puts [1].join("0") > puts [1, nil].join("0") > > m. Thanks. Back to the documentation. Misunderstanding - thought join meant adding the argument string to the array element. I see that the argument is a separator between elements. Duh! Easy to miss these things at my age (70). Len