6 ms·
I like the refinements mechanism too and it is most certainly underutilized, but the lexical scope makes it an incomplete substitute, and somewhat problematic d
by inopinatus 5y ago
I like the refinements mechanism too and it is most certainly underutilized, but the lexical scope makes it an incomplete substitute, and somewhat problematic during reflection.
- chrisseaton 5y agoI'm not an expert but I believe the lexical scoping was a last-minute save by Charlie Nutter to preserve performance! Dynamic scoping of method definitions is seriously hard to optimise, and I'm not sure anyone knows how to do it. Do you really need dynamic? Why isn't lexical enough?
- inopinatus 5y agoTo clarify, I don't need it, and I'd agree that any library interface using monkeypatching could in principle be redesigned to use refinements. What I'm suggesting is in practice, I suspect it's doubtful anyone would undertake the exercise of reframing ActiveSupport (and thereby the entire Rails ecosystem) to use refinements instead of core extensions.
- lamontcg 5y agoNobody should rewrite rails and activesupport and the entire ecosystem using refinements. It would be a massively breaking change for little purpose because activesupport is so well known to the core ruby team. Nobody who is greenfielding code should copy the activesupport pattern, though, and you aren't losing anything by being told not do that, you're being shown a better way.