Hi --

On Mon, 22 Jan 2007, William James wrote:

> dblack / wobblini.net wrote:
>>
>> I'll put in a plug here for flattenx, which lets you flatten by any
>> number of levels so that you could do the above without the
>> over-flattening vulnerability.
>>
>> http://raa.ruby-lang.org/project/flattenx/
>
> class Array
>  def flatten_1
>    inject([]){|a,x| Array(x).each{|e| a<<e}; a}
>  end
> end
>
> p [[[[22],33],44], %w(aa bb cc), [88,[99,55]], 3.14].flatten_1
>
> ---  output  -----
> [[[22], 33], 44, "aa", "bb", "cc", 88, [99, 55], 3.14]

That's the idea, though flattenx lets you do flatten_by(n) and also is
written in C for speed.


David

-- 
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
    (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)