ES schrieb:
> Wouldn't it be possible to override the TrueClass, NilClass
> and FalseClass methods to yield the correct behaviour for
> this object? I'm assuming 'if something' expands to
> 'if something == true' or something like that?

If you look at the Ruby source code (this is 1.8.2), in eval.c:

       case NODE_IF:
	if (trace_func) {
	    call_trace_func("line", node, self,
			    ruby_frame->last_func,
			    ruby_frame->last_class);
	}
 >>>	if (RTEST(rb_eval(self, node->nd_cond))) {
	    node = node->nd_body;
	}
	else {
	    node = node->nd_else;
	}
	goto again;

This is the code to handle an if statement. The marked line is the code that 
evaluates the condition. The "then"-part of the if statement is executed iff the 
RTEST macro returns true (in C). RTEST is defined in ruby.h as:

	/* special contants - i.e. non-zero and non-fixnum constants */
	#define Qfalse 0
	#define Qtrue  2
	#define Qnil   4

	#define RTEST(v) (((VALUE)(v) & ~Qnil) != 0)

The objects false, true, and nil are encoded internally as 0, 2, and 4 
respectively. (You can get those values in Ruby with "p false.id".) The only 
values for which RTEST returns false (in C) are the values 0 and 4, in other 
words the objects false and nil. So more or less

   if something

expands to

   if something != nil && something != false

I think Christian is right that you cannot work around this in Ruby. (Maybe 
Florian Gro? can do it...)

Regards,
Pit