Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module Configurable
def config(*attrs)
@configuration ||= Struct.new(*attrs).new
end
def configure
yield(@configuration) if block_given?
end
end
class ApiGateway
extend Configurable
config :api_key, :api_host
end
ApiGateway.configure do |config|
config.api_key = '<API Key>'
config.api_host = '<http://example.com>'
end
ApiGateway.config
=> #<struct api_key="<API Key>", api_host="<http://example.com>">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment