Our Daily Method #18: NilClass#method_missing

Geplaatst door Remco van 't Veer

Warning: only apply the following under parental guidance!

We know the whiny nil, as applied in Rails, but what about an obedient nil:

class NilClass def method_missing(*args) nil end end

No more monkeying like:

person && person.name && person.name.upcase

Not DRY at all! Let’s use the obedient nil instead:

person.name.upcase

This concludes our last daily method. Ode to Michiel for providing a vast amount of nice tricks!