Todd Benson
3/12/2008 1:01:00 AM
On Tue, Mar 11, 2008 at 6:32 PM, Jeremy Weiskotten
<jeremy.weiskotten@gmail.com> wrote:
> Aryk Grosz wrote:
> > Is there any prettier or cleaner way to write
> >
> > x = [x] unless x.is_a?(Array)
>
> x = [x].flatten
>
> Although I suspect the x = Array(x) method would be faster.
Yeah, but those are a little different, too...
x = [[1, 2, 3], [1, 2]]
p x.flatten
=> [1, 2, 3, 1, 2]
x = [[1, 2, 3], [1, 2]]
p Array(x)
=> [[1, 2, 3], [1, 2]]
Todd