From: Srijayanth Sridhar Date: 2009-05-05T16:23:45+09:00 Subject: a DSL + scope problem --001e680f1240a0d4d1046925283a Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hello, Wrt: http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/689cbe271d680979/5ba5a52ba929b142?lnk=raot&fwc=2&pli=1 Basically I have a log file where different lines need to be mapped to different statements, for instance: "Look a shiny red Ferrari!" -> "Italian metal" However, it is not a simple mapping alone, there also needs to be some intelligence and a state needs to be kept in order to determine some other fancy stuff. Anyway, the point is, I had an ugly design involving abstract classes and so on, I've gone on to making a DSL where a person can do the following: # rule name is fairly pointless, just used to trigger the method_missing call :) rule_name /regEx/ do |line| # process the line, apply logic # Return a mapped new string end Basically what the DSL lets them do is define rules and associated blocks on certain regexes which all gets put into a table. This has simplified things a lot, and all they do is create rules. Its all working fine, but now I want to add another feature. I want to define some common methods in the DSL class(like formatting strings a certain way etc), but I want this to be available to the people who define the rules and the blocks and use the DSL. Ideally this is easily accomplished by passing self into the blocks. But I don't want to burden these chaps with what self is and so on, and generally speaking passing self seems a little ugly. Is there any other method you guys can suggest? The DSL is being instance_eval-ed... Thank you, Jayanth --001e680f1240a0d4d1046925283a--