Last active
December 19, 2015 10:59
-
-
Save nzaillian/5944541 to your computer and use it in GitHub Desktop.
My personal pattern for storing configuration info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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