From: Austin Ziegler Date: 2005-11-17T06:50:24+09:00 Subject: Re: Object#to_b On 11/16/05, Daniel Schierbeck wrote: > Currently, as far as I know, `if' and `unless' merely check if an object > is of either types NilClass or FalseClass. This seems to contradict the > duck-typing paradigm. I propose that we implement a method Object#to_b > that is called by `if' and `unless'. It should return a boolean value. > That way, a developer can decide whether or not an object should > evaluate to true or false. > One problem I see with this proposal is that it seems like a lot of > people check if a variable has been set by writing `if var ...'. This > change would require that people wrote `unless var.nil?', which I > personally find more correct as well. This would break a lot of my code, personally. I used to use "unless var.nil?" but it is easier to say: if var and var.foo than: if (not var.nil?) and var.foo I'm not *quite* sure what the "unless" version of the test would be: unless var.nil? or var.foo.nil? Not quite what I want. I think that #to_b would be problematic, especially in the example that you gave, since it's more expressive to say: if conn.open? than: if conn which implies you're checking to see if conn is really there. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca