From: "Jan E." Date: 2012-08-11T02:02:52+09:00 Subject: Re: Help with database-related code pls Kaye Ng wrote in post #1071965: > Thank you Rex, but how is it an array of hashes? > > 'puts person.inspect' returns: > > {"id"=>3, "name"=>"Dave Ellefson", "job"=>"Bassist", "gender"=>"Male", > "age"=>47, 0=>3, 1=>"Dave Ellefson", 2=>"Bassist", 3=>"Male", 4=>47} > > Isn't {key => value, key => value, etc. etc} just a Hash? (not an array > of hashes) Yes it is. And that was to be expected, because "person" is the result of the "first" method. So it's the first row of the table. I guess this was a misunderstanding, and they actually wanted you to inspect the query result (without the "first"). However, this probably won't reveal anything useful. I'm pretty sure it's not an actual array of hashes but rather some kind of result object (which only behaves like an array). Anyway, do you understand now why there's a "first"? Calling "execute" returns some kind of enumeration object for the rows of the query result. And if you want to get a specific row, you have to fetch it from this object. You can also call "each" on the result to loop through the rows: result = $db.execute("SELECT * FROM people WHERE name = ? OR id = ?", idorname, idorname.to_i) result.each do |row| p row end This should display all rows one after another. -- Posted via http://www.ruby-forum.com/.