Hello,
Wrt:
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