Submitted by coreywangler (Wed Jan 14 02:01:29 UTC 2004)
Adding TrueClass#not and FalseClass#not instance methods allows for clearer code in some cases, by allowing chaining of method calls with the ".not" method.
There is currently no ".not" method for boolean objects.
Add TrueClass#not and FalseClass#not instance methods.
class TrueClass def not not self end end class FalseClass def not not self end end a=nil a.nil?.not #==>false a=3 a.nil?.not #==>true
Makes it easy to express things the object-oriented way, by chaining method calls. This can make code clearer in some cases.
Addition to the language (for speed and efficiency) the equivalent of this Ruby code...
class TrueClass def not not self end end class FalseClass def not not self end end
Comments | Current voting | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
RCRchive copyright © David Alan Black, 2003-2005.
Powered by .
Note that there are some predicates that do not return boolean values, for example, "defined?" gives string description of the expression if defined, otherwise returns nil.
Consequently, adding "not" method to TrueClass and FalseClass is not enough. Options are:
I don't think changing all predicates are not worthy. And I feel kind of reluctant to adding "not" to every object.
-matz.
Withdrawing RCR
Yeah, adding to Object is not good.
- corey.