Ned Konz <ned / bike-nomad.com> wrote in message > 
> ----------- assert.rb -----------
> class AssertionFailure < StandardError
> end
> 
> class Object
>   def assert(bool, message = 'assertion failure')
>     if $DEBUG
>       raise AssertionFailure.new(message) unless bool
>     end
>   end
> end
> --------- assertTest.rb -----------
> require 'assert.rb'
> assert(true, "testing true")
> assert(false, "testing false")
> --------------------------------------


This is very nice, but I wonder if Ruby can simulate a stringizing
assert macro from C, which I find more elegant:

#define assert(x)(x || fprintf(stderr, "Assertion failed: %s\n", #x))

Thus, in C, the assertion

   assert(x != 1);

if violated would print out

    Assertion failed: x != 1

The assertion expression gets evaluated, as well as converted into a
string for printing to standard error.  Is it possible to do this in
Ruby?

Damon