From: Michael Neumann Date: 2001-12-15T00:14:51+09:00 Subject: [ruby-talk:28508] Re: how can this work correctly? Jack Dempsey wrote: > hi all, > > just cruising through the standard example the comes with the Ruby > DBI...i'm getting an error at this part: > > puts "selecting..." > dbh.select_all('select * from simple01') do > p row > end Oops, I though I fixed that. Correctly it should look like this: puts "selecting..." dbh.select_all('select * from simple01') do | row | p row end > it can't find row...which makes sense to me, but this is verbatim code > from the docs which come with the DBI...if i make it do |x| p x it'll > work, but is this supposed to work and i'm missing something? > is there any way to do it even shorter than this > > puts "selecting..." > dbh.select_all('select * from simple01') do |x| p x end To output all rows, just use the non code-block version of method select_all. p dbh.select_all('select * from simple01') I think there's no shorter way, not even in Perl ;-) Alternatively use { and } instead of "do" and "end": dbh.select_all('select * from simple01') {|x| p x} > something like the $_ var in perl...i know ruby has $_, but seems > different... I don't think it would be a good idea to assign $_ before yielding control to the specified code block. And, writing half a dozen more characters shouldn't be a problem. Regards, Michael -- Michael Neumann merlin.zwo InfoDesign GmbH http://www.merlin-zwo.de