Pixel wrote:

> class Array
>   def flatten_once
>     l = []
>     each{|l1| l += l1}
>     l
>   end
> end

Using the standard "inject" (see pickaxe, for example), you can do the
same with:

your_list.inject ([]) { |sum, x| sum + x }

But both of these might not do what you want with a list like [1, [2,
3]] that has non-arrays at the top level. That can be fixed with:

[1, [2, 3]].inject ([]) { |sum, x| sum + x.to_a }

# ==> [1, 2, 3]

--
Joel VanderWerf                          California PATH, UC Berkeley
mailto:vjoel / path.berkeley.edu                     Ph. (510) 231-9446
http://www.path.berkeley.edu                       FAX (510) 231-9512