Closed tastycode closed 10 years ago
I wrote an article about this: http://devblog.avdi.org/2011/05/30/null-objects-and-falsiness/
Bottom line, trying to make a non-nil object act "falsy" is a fool's errand in Ruby.
I mean, you can override unary !
to do what you want in Ruby, but that's just going to make the cases you can't control less consistent.
You are right... i don't want to know.. i just want to do nothing in most cases. I just don't want one of these special objects getting too far out there.
So, I would love to use this, but it doesn't really mimic nil
with ruby
with naught
I at least need null objects to have the "truthiness of false", that is when
!!Null.new == false
I know that I'm probably not "thinking of this from the right perspective", could you enlighten me?
Just for fun, I ventured to see if i could get the behavior i was looking for, but had to use refinements as defining method on nil actually modifies all nil :(