HN.zip

Moment of Ruby: An Argument for Nothing

37 points by zemptime - 6 comments
matharmin [3 hidden]5 mins 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.
thisismyopinion [3 hidden]5 mins ago
Please fix the indentation of the code -_-
koolba [3 hidden]5 mins 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.

XYen0n [3 hidden]5 mins ago
This expression returns true. It should be in a different scope from the default parameter value, so I assume it is equivalent to passing true directly.
semiquaver [3 hidden]5 mins ago
Wow, I wrote Ruby for 15+ years and never saw this trick!
rubyfan [3 hidden]5 mins ago
Same and it’s really unclear to me why you would want this access pattern over. It seems like it might lead to unintended consequences.