Skip to content

Instantly share code, notes, and snippets.

@everm1nd
Created October 16, 2012 16:59
Show Gist options
  • Save everm1nd/3900563 to your computer and use it in GitHub Desktop.
Save everm1nd/3900563 to your computer and use it in GitHub Desktop.
Simple DSL at Ruby
class DSL
def initialize &block
@params = {}
instance_eval &block
end
def param key, value
@params[key] = value
end
def to_s
@params.to_s
end
def [] key
@params[key]
end
def []= key,value
@params[key] = value
end
end
config = DSL.new do
param :a, 1
param :b, 2
end
config[:c] = 15
puts config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment