Skip to content

Instantly share code, notes, and snippets.

@sstelfox
Created November 15, 2013 03:02
Show Gist options
  • Save sstelfox/7478430 to your computer and use it in GitHub Desktop.
Save sstelfox/7478430 to your computer and use it in GitHub Desktop.
Simple DSL pattern for configuration
require 'singleton'
Config = Struct.new(:a, :b)
class Config
include Singleton
def self.[](arg)
instance.public_send(arg.to_sym)
end
def self.config
yield instance
end
end
Config.config do |c|
c.a = "something"
c.b = "else"
end
puts Config[:a]
puts Config["b"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment