Skip to content

Instantly share code, notes, and snippets.

@nzaillian
Last active December 19, 2015 10:59
Show Gist options
  • Save nzaillian/5944541 to your computer and use it in GitHub Desktop.
Save nzaillian/5944541 to your computer and use it in GitHub Desktop.
My personal pattern for storing configuration info
# The personal pattern I've devised for storing module or app-wide configuration
# info in ruby projects
require 'ostruct'
module SomeApp
class Configuration
def self.method_missing(*args)
config.send *args
end
private
def self.config
@@config ||= OpenStruct.new
end
end
end
# all assignments/reads on SomeApp::Configuration.any_configuration_var now
# get delegated to a private OpenStruct singleton owned by SomeApp::Configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment