2 ms·
The encapsulation here is exactly the same as you would have in a 6-line function. And here’s a bonus: the testability is exactly the same in both cases too (u
by whstl 3y ago
The encapsulation here is exactly the same as you would have in a 6-line function.
And here’s a bonus: the testability is exactly the same in both cases too (unless you’re breaking encapsulation in your tests — another thing that’s awfully common in Rails).
The only difference is the readability. With a 6-line function you have perfectly readable code without jumping around.
- vidarh 3y agoAs I think we've both pointed out, it's actually less encapsulated, since you can do dirty stuff like `send` or `instance_eval`, while we can't "break into" the internal state of a single method.