From: kjana@...4lab.to (YANAGAWA Kazuhisa) Date: 2002-07-26T19:11:12+09:00 Subject: Re: [PATCH] object.c ruby.h (fwd) In message Dave@PragmaticProgrammer.com writes: > So, perhaps, if the expression to pass to 'if', 'while', and friends > isn't 'true' or 'false', the interpreter should call #truth? on it to > coerce it into a truth value.[1] > > If that sounds logical, then perhaps #to_truth might be a more > consistent name. That's like my old proposal on.... where? :-) Matz rejected that since its cost may be too expensive. So if you state it strongly, show its usefulness and effective implementation. > [1] Doing this would allow Perl fans to do > > class String > def truth? > !empty? > end > end > class Integer > def truth? > !zero? > end > end My proposal is inspired by a discussion on Regexp.last_match, where someone said `/re/.match() should return always MatchData'. To solve its compatibility problem, introducing a conversion method like to_ary or to_int then we can write `if /re/.match() ...' again, where MatchData#to_bool returns true if matched, false else. # Uhm, a bad summary :-P -- kjana@dm4lab.to July 26, 2002 Translators, traitors.