"David A. Black" <dblack / wobblini.net> schrieb im Newsbeitrag
news:Pine.LNX.4.44.0406041648060.6593-100000 / wobblini...
> Hi --
>
> On Sat, 5 Jun 2004, Michael Neumann wrote:
>
> > On Sat, Jun 05, 2004 at 03:34:47AM +0900, Edgardo Hames wrote:
> > > Hi, everybody. I would like to use an assert like function to test the
> > > number of rows returned by a query. Something like Eiffel's
> > >
> > > check result.num_rows = 1
> > >
> > > What's the best way to do that in Ruby?
> >
> >   def check
> >     raise "check failed" unless yield
> >   end
> >
> >
> >   check { result.num_rows == 1 }
>
> I guess you could even do:
>
>   def check(a)
>     raise "check failed" unless a
>   end
>
>   check result.num_rows == 1
>
> though of course that wouldn't scale if the assertion got more complex
> syntactically.  (I'm not sure it's any better anyway, but I was trying
> to match Edgardo's sample syntax as closely as I could.)

IMHO the block form is better since the block is only evaluated if DEBUG is
switched on, while in your case the expression always evaluate.

Regards

    robert