From: John Joyce Date: 2007-10-10T02:29:21+09:00 Subject: Re: Make a class evaluate to false in boolean expressions On Oct 9, 2007, at 10:53 AM, Matt Margolis wrote: > I want to have a class that always evaluates to false in boolean > expressions. Is there a way to extend Ruby so that it evaluates an > object of a class to false like false and nil? > > Example > > class AlwaysFalse > end > > should_be_false = AlwaysFalse.new > > if should_be_false > #I don't want this to ever run > else > #will always run > end This is your design problem. You can't change the language to do what it doesn't do. What you want is probably not a class if it always returns false. You want a constant value. You can create a class with an instance or class variable that happens to be a constant. (no setter, only a getter) so you might do The problem is your if will go to else if the should_be_false is false. not clear logic in the code. Just do it the Ruby way, create a method or function: my_class.false? or false?( my_arg ) This way the logic is more obvious and clear like natural language.