Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demonstrating a flexible DSL for configuration .
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
You can’t perform that action at this time.