You cannot achieve this.
s.nil? return value equal to either true or false , which are the only instances of TrueClass and FalseClass , respectively. You cannot create other instances of these two classes. Therefore, you cannot patch the monkey TrueClass or FalseClass remember the context s . You can define the singleton or method to true and false , however, it does not know anything about s , so you cannot associate another predicate empty? .
def true.or other true end def false.or other other end
You can write s.nil?.or(s.empty?) With the specified two helper methods.
Another thought is to return a customized object for all predicate methods (blabla?), Not true or false . However, in ruby ββonly nil and false give a lie, any other things give true. An instance of a personalized object will always be true, which will break all these predicate methods.
source share