From: Patrick Li Date: 2008-08-11T02:53:10+09:00 Subject: Re: DSL challenge. Do you guys have any elegant ideas? Thanks for all the solutions. I've looked through every one of them and here's my thoughts. Joel VanderWerf: This is the ideal functionality. It's easily extendable. Very nicely object-oriented. And it was the first design that I actually used. Unfortunately, having to explicitly call the receiver object every time is not very elegant. Which lead to me using instance_eval to get around it. The problem I was having with instance_eval is this: instance_eval messes up your scope. Which is counterintuitive from the users point of view. i.e. the user cannot call private helper methods from within Farm.create def barnCreator barn do animal "Dog" end end Farm.create do barnCreator #throws illegalmethoderror end Ara Howard: I think your solution solves the scope problems really nicely. Your code library is pretty advanced though. I'm going to need to understand it a little more fully before I can make a judgement. Eric I: I notice that your manually controlling the "stack frame" to restrict access to certain methods. But you're using class_eval also, whose scope changes will run into the same problems as instance_eval. I'm going to need to read through your code more carefully also to understand it. So I guess the cleanest solution is still Joel's. But I just need a way to implicitly specify the receiver without changing scope and killing all my closures. Thanks very much for your help guys. I definately learned a lot from your solutions. -Patrick -- Posted via http://www.ruby-forum.com/.