HTML5 Canvas
Written by: Simon Sarris
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Web Driver
  3. MVVM
  4. REST
  5. ADO.NET
  1. HTML5
  2. Ajax
  3. jQuery Selectors
  4. CSS Part 1
  5. Git

Link Details

Link 25416 thumbnail
User 227746 avatar

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.
  • 7
  • 0
  • 1595
  • 0

Comments

Add your comment
User 227746 avatar

Shadowfiend replied ago:

0 votes Vote down Vote up Reply

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 :-)

User 107114 avatar

daniel replied ago:

0 votes Vote down Vote up Reply

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. :-)

User 227746 avatar

Shadowfiend replied ago:

0 votes Vote down Vote up Reply

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.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (7)



Voters Against This Link (0)