Moment of Ruby: An Argument for Nothing

(aha.io)

32 points | by zemptime 2 days ago

3 comments

  • matharmin 52 minutes ago

    It's an interesting trick, but for a setter method you really need to use `def cloaking=(value)` instead of overloading the same method. It would help to give a more realistic example for where this technique can be useful.

    • koolba 14 minutes ago

      What happens if you pass in (nothing_provided = true) as the value?

      Does it return back the empty current value?

      I’m no ruby expert, but seems like the freeze approach avoids that with a unique inaccessible object.

      • semiquaver 43 minutes ago

        Wow, I wrote Ruby for 15+ years and never saw this trick!