From: Caleb Clausen Date: 2010-02-16T05:57:09+09:00 Subject: Re: "Code must be Chunkable" On 2/15/10, Intransition wrote: > On Feb 15, 4:24 am, Caleb Clausen wrote: > >> When people say things like this, it makes me think there ought to be >> a way to do it by using RubyMacros. So, I tried to rewrite Tom/Brian's >> code as macros... I think I can get rid of the need to call extend or >> use method_missing/proxies. But I had to use a feature of RubyMacros >> that I haven't invented yet (motivation!) and I may be missing the >> point (esp as I didn't watch the movie). Since I don't know if it >> would even work, I'm reluctant to post the example I came up with,,, >> but if anyone really wants to see it, I will. > > Personally I think Mr. Mittag is overstating the issue. I haven't seen > anything yet to indicate that DCI is beyond implementation in regular > Ruby. But then maybe I am misunderstanding some key elements --I would > love to know. In any case, feel free to show us your code, even if it > is just an exercise in what can be done with RubyMacros. Since writing that, it occurred to me that the same effect could be achieved with regular old eval. There's always an eval equivalent to any use of macros, but in this case the result is actually pretty clean. So, here's my eval-based version: http://gist.github.com/304558 What I did differently: creation of the context subclass I consigned to a utility method, since that appears to be boilerplate code. The role class has disappeared entirely, replaced by hashes. The result is less orthodox than the classes-and-modules approach used by brian and yourself... but I think the minimal amount of code that users of this context library have to write is particularly nice. I may have made too many static assumptions, such as: Balance::Transfer#transfer always just calls #transfer on its child Roles Those roles in turn simply forward the #transfer message to some other method(s) (increaseBalance and decreaseBalance in this case) Please let me know what you think of this.