Skip to content

Instantly share code, notes, and snippets.

@happyrobots
Created September 22, 2011 20:36
Show Gist options
  • Save happyrobots/1235965 to your computer and use it in GitHub Desktop.
Save happyrobots/1235965 to your computer and use it in GitHub Desktop.
Configuration Patterns
module MyCoolModule
class Configuration
attr_accessor :my_value
def initialize
# set defaults
end
end
def self.configure
@@config = MyCoolModule::Configuration.new
yield(@@config)
end
def self.initialize!
@@config.do_something if @@config
end
end
MyCoolModule.configure do |config|
# override defaults
end
MyCoolModule.initialize!
require 'active_support/ordered_options'
module MyCoolModule
def self.configure
@@config = ActiveSupport::OrderedOptions.new
yield(@@config)
end
def self.initialize!
do_something(@@config)
end
end
MyCoolModule.configure do |config|
# Define anything
end
MyCoolModule.initialize!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment