From: Johan Holmberg Date: 2004-01-16T00:03:39+09:00 Subject: Re: Concatenating variable number of Arrays ? On Thu, 15 Jan 2004, Robert Klemme wrote: > "Florian Frank" schrieb im Newsbeitrag [...] > > If you extend Symbol like this: > > > > class Symbol > > def to_proc > > lambda { |a, b| a.__send__(self, b) } > > end > > end > > > > You could also write > > > > arr2 = arr1.inject([], &:+) > > > > That's pretty similar to how it is done in most functional programming > > languages. > > Amazing! Only that it's less efficient since your approach creates more > temporary arrays. > I agree. Where can I read about 'to_proc' and how it works ? To avoid "+" I tried to changing to "concat" and this seems to work too: class Symbol def to_proc lambda { |acc, x| acc.__send__(self, x) } end end arr1 = [ [1,2,3], [4,5,6], [7,[8,9]] ] arr2 = arr1.inject([], &:concat) /Johan Holmberg