A DSL implementation based on Bundler
Here is an implementation of a real basic DSL. The implementation was lifted from bundler.
The main idea is you have a class
Dsl that you call
instance_eval on. Your domain specific language is still written in ruby, but by evaluating it within the context of an instance of
Dsl, you can create the illusion of top level language constructs. These are merely public instance methods of
Dsl. This is the way bundler evaluates a
Here is an example, using the implementation in the gist below.
dsl = Remote::Dsl.new dsl.server :app1, "email@example.com" dsl.server :app2, "firstname.lastname@example.org"
instance_eval we can turn the above into
server :app1, "email@example.com" server :app2, "firstname.lastname@example.org"
Examples of this type of DSL:
- config/routes.rb in Rails