From: "rosenfeld (Rodrigo Rosenfeld Rosas)" Date: 2013-04-16T21:07:27+09:00 Subject: [ruby-core:54337] [CommonRuby - Feature #8273] Make it possible to treat objects as falsy in order to make NullObjects more convenient Issue #8273 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas). I should agree with Charles although I understand Ilya's concerns. Maybe another attempt to get this implemented would be simply requesting native support for a NullObject class in such a way that falsey would be either false, nil or an instance of NullObject. What do you think about such proposal? ---------------------------------------- Feature #8273: Make it possible to treat objects as falsy in order to make NullObjects more convenient https://bugs.ruby-lang.org/issues/8273#change-38614 Author: prijutme4ty (Ilya Vorontsov) Status: Open Priority: Normal Assignee: Category: Target version: NullObject is quite a useful pattern. But refactoring from conditionals to null-object can be very painful because an instance of NullObject will be treated as truthy so code `... if obj` can change its behavior. It'd be great to treat such objects as falsy. Most simple and consistent solution is to make method like #to_boolean or may be #__to_bool (not to break compatibility) which returns false for NilClass and FalseClass and true otherwise unless redefined. I don't know whether perfomance impact'll be high or no. It's one of a few things which cannot be reimplemented using ruby itself, so there is no possibility to construct a gem as a PoC -- http://bugs.ruby-lang.org/