Ruby efficient way of building an array from an array of arrays

Posted by randombits on Stack Overflow See other posts from Stack Overflow or by randombits
Published on 2010-04-24T02:26:55Z Indexed on 2010/04/24 2:33 UTC
Read the original article Hit count: 297

Filed under:
|

I have an array of ActiveRecord objects, each one which has its own respective errors array. I want to flatten it all out and get only the unique values into one array. So the top level array might look like:

foo0 = Foo.new
foo1 = Foo.new
foo2 = Foo.new
foo3 = Foo.new

arr = [foo0, foo1, foo2, foo3]

Each one of those objects could potentially have an array of errors, and I'd like to get just the unique message out of them and put them in another array, say called error_arr. How would you do it the "Ruby" way?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails