Using Enumerable#inject we can do the task in one loop:
a = [
["Francis", "Chartrand", "email@email.com"],
["Francis", "Chartrand", "second_email@email.com"]
]
a.inject(nil) {|str, arr| str ? (str << ', ' << arr[2]) : arr[2].dup}
#=> "email@email.com, second_email@email.com"
However, this is an academic thing only, because map
/join
is faster and more readable anyways. See this benchmark:
user system total real
map/join 1.440000 0.000000 1.440000 ( 1.441858)
inject 2.220000 0.000000 2.220000 ( 2.234554)