Object#to_bool
class Object
def to_bool
self ? true : false
end
end
Why? To get rid of the following patterns:
not @foo.nil?
@foo ? true : false
!!@foo
One could argue that the object itself already acts as a boolean value, but I really prefer to use real boolean (true
/false
) when they are expected.