Created
January 15, 2019 18:42
-
-
Save andriy-baran/48b8857bf100b584661f79b1da4f32e2 to your computer and use it in GitHub Desktop.
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
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