Skip to content

Instantly share code, notes, and snippets.

@prdanelli
Created November 9, 2021 09:36
Show Gist options
  • Save prdanelli/bcfb45975753b02d8fa7e2b404b29e6c to your computer and use it in GitHub Desktop.
Save prdanelli/bcfb45975753b02d8fa7e2b404b29e6c to your computer and use it in GitHub Desktop.
Create a configuration class
# Usage:
#
# Settings.configure do |c|
# c.foo = "biz"
# c.bar = "boo"
# end
# Test.config.foo
# => "biz"
# Test.configured?
# => true
# Test.reset!
# => nil
# Test.configured?
# => false
# Test.config.foo
class Settings
def self.config
@config ||= Struct.new(:foo, :bar).new
end
def self.configure
yield(config)
end
def self.configured?
!!@config
end
def self.reset!
@config = nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment