From: Michael Neumann Date: 2002-09-27T02:41:59+09:00 Subject: Re: Weird Array.flatten behaviour with DBI Travis Whitton wrote: > Hello, I'm having a weird issue with the Array.flatten method when using > it with DBI. The problem is that it doesn't seem to flatten out results > returned from sth.fetch_all. I rolled my own flatten, but I'd rather > use Ruby's builtin flatten. Here's the code I'm working on: > > require 'dbi' > > class Test > def initialize > @lims = DBI.connect("DBI:Mysql:lims", "myuser", "mypass") > end > > def flatten(list) > (!list) ? [] : > ((list[0].type == Array) ? flatten(list[0]) : list[0].to_a) + Method fetch_all returns DBI::Row objects, not Arrays! Use to_a to convert a DBI::Row into an array. Regards, Michael