Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nmarley
Last active January 1, 2016 10:09
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 nmarley/8129647 to your computer and use it in GitHub Desktop.
Save nmarley/8129647 to your computer and use it in GitHub Desktop.
Ideal implementation of TradeAPI - factors out details of retrieving key/secret
#! /usr/bin/env ruby
class TradeAPI
attr_accessor :key
attr_accessor :secret
def initialize(key, secret)
@key = key
@secret = secret
unless @key && @secret
# throw exception, key and secret must be set
raise ArgumentError, "Both key and secret must be set."
end
end
end
#t1 = TradeAPI.new
t2 = TradeAPI.new('keyisthekey', 'übersecret')
puts "t2 key = #{t2.key}"
puts "t2 secret = #{t2.secret}"
t2.key = 'GrandMasterKey!'
puts "t2 key = #{t2.key}"
puts "t2 secret = #{t2.secret}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment