Skip to content

Instantly share code, notes, and snippets.

@andriy-baran
Created January 15, 2019 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andriy-baran/48b8857bf100b584661f79b1da4f32e2 to your computer and use it in GitHub Desktop.
Save andriy-baran/48b8857bf100b584661f79b1da4f32e2 to your computer and use it in GitHub Desktop.
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