32 points | by zemptime 2 days ago
3 comments
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.
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.
Wow, I wrote Ruby for 15+ years and never saw this trick!
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.
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.
Wow, I wrote Ruby for 15+ years and never saw this trick!