Skip to content

Instantly share code, notes, and snippets.

@jimweirich
Created October 2, 2013 01:12
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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