Created
October 2, 2013 01:12
-
-
Save jimweirich/6787708 to your computer and use it in GitHub Desktop.
Demonstrating a flexible DSL for configuration .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def project(name, &block) | |
Project.new(name, &block) | |
end | |
class Project | |
def initialize(name, &block) | |
@name = name | |
@context = eval("self", block.binding) | |
instance_eval(&block) if block_given? | |
end | |
def use_pthreads | |
puts "PTHREADS" | |
end | |
def link_with(lib) | |
puts "LINKING WITH #{lib}" | |
end | |
def method_missing(sym, *args, &block) | |
@context.send(sym, *args, &block) | |
end | |
end | |
class Builder | |
def build | |
project "myProject" do | |
use_pthreads | |
link_with libraries_to_link_with | |
end | |
end | |
def libraries_to_link_with | |
%w(a b c) | |
end | |
end | |
Builder.new.build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment