I want to create a class Nilly to obtain a “pseudo-nil” object, but I need it to be evaluated as boolean false.
e.g.:
class Nilly; end
n = Nilly.new
puts n ? 'true' : 'false' #=> I want false here
How can I do that?
P.S.: I tried to do class Nilly < NilClass, but I coudn’t use the new method (it was stripped out in NilClass).
Boolean logic in Ruby ONLY allows
nilandfalseto befalsyEverything else is
truthy.There is no way to do this.
May I ask why you want this?
What is special about your
Nillyclass?I suggest you just call it a different way.
And use this in your logic