Project

General

Profile

Actions

Feature #8273

closed

Make it possible to treat objects as falsy in order to make NullObjects more convenient

Added by prijutme4ty (Ilya Vorontsov) about 11 years ago. Updated over 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:54303]

Description

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


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #6180: to_b for converting objects to a boolean valueRejectedmatz (Yukihiro Matsumoto)03/21/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0