By Shadowfiend
via blog.withoutincident.com
Published: Jun 13 2007 / 03:32
An implementation of `with' for Ruby that gets around limitations shown by some of the more common implementations (including an earlier one of my own) by using a proxy object and some other magic to create a version that functions very similarly to the Javascript keyword of the same name.
Comments
Shadowfiend replied ago:
It bears mentioning, by the way, that this is largely just a neat exhibition of some of Ruby's metaprogramming magic. The with statement itself isn't *that* useful, I think, and this implementation in particular is probably slow enough to not merit the tradeoff. But the implementation is (IMO) kinda neat :-)
daniel replied ago:
Personally, I think he should have stuck with the instance_eval implementation. After all, Ruby is all about trusting programmers to follow the rules (typing, method checking etc...) and the result has been some impressively dynamic algorithms. Why not just carry that to the next level and trust developers to respect encapsulation? After all, if it's not in the public API and you're using it, it's your own fault if something goes wrong. :-)
Shadowfiend replied ago:
Yes, but sticking with instance_eval is kind of useless. After all, if you're going to use instance_eval, use instance_eval :-) with is supposed to operate differently -- in a more limited way, encapsulation-wise, and a broader way, in terms of the access to the original binding scope.
Voters For This Link (7)
Voters Against This Link (0)