Constants are a kind of global variable. Classes get free constants.
You can use something like the Singeton pattern:
module XmlRpc
def self.login(user, pass)
@user = user
@client = = XMLRPC::Client.new(...)
@session_id = @client.call("xmlrpc.method", $user, $pass)
end
def self.user() @user or raise "Not initialized" end
def self.client() @user or raise "Not initialized" end
def self.session_id() @session_id or raise "Not initialized" end
end
Then you can login globally like so:
XmlRpc.login("me", "my_password")
Then elsewhere you can use:
client = XmlRpc.client
session_id = XmlRpc.session_id
(Which will throw an exception if you're not logged in yet)
What do you think? It's still global.
Of course another idea is to use a single global, a Hash or OpenStruct,
for these related data points: $xmlrpc[:session_id]
Cheers,
Dave