Skip to content

Instantly share code, notes, and snippets.

@jimweirich
Created October 2, 2013 01:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimweirich/6787708 to your computer and use it in GitHub Desktop.
Save jimweirich/6787708 to your computer and use it in GitHub Desktop.
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