From: Jean-Hugues ROBERT Date: 2004-06-05T05:51:44+09:00 Subject: Re: Check assertion in Ruby At 03:41 05/06/2004 +0900, you 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 } > >Regards, > > Michael if DEBUG def assert raise "assertion failure" unless yield end else def assert; end end There is some overhead when not in DEBUG mode, but that is the best you can do in Ruby as far as I know. Yours, Jean-Hugues ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17