Skip to content

Instantly share code, notes, and snippets.

@mehdi-farsi
Created September 23, 2018 22:26
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 mehdi-farsi/135d516254ae690335da0b14c13ed83b to your computer and use it in GitHub Desktop.
Save mehdi-farsi/135d516254ae690335da0b14c13ed83b to your computer and use it in GitHub Desktop.
require 'singleton'
class Client
include Singleton
attr_accessor :url, :port, :credentials
end
class DBClient < Client; end
class ApiClient < Client; end
db = DBClient.instance
db.url = 'https://10.11.12.13'
db.port = 4242
db.credentials = 'username:password'
api = ApiClient.instance
p api.url # => nil
p api.port # => nil
p api.credentials # => nil
api.url = 'https://14.15.16.17'
api.port = 8484
api.credentials = 'username:password'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment