Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
More elegant replacement for global variables
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Trans, post: 4481783"] Avoid globals by using container classes/modules. In your cace you might use the base class itself. class Base class << self attr_accessor :user, :pass attr_reader :client, :sessionid def login(user=nil,pass=nil) @user = user if user @pass = pass if pass @client = XMLRPC::Client.new(...) @sessionid = @client.call("xmlrpc.method", @user, @pass) return @sessionid end end def initialize if not self.class.sessionid then self.class.login end end end class Object1 < Base def initialize() super end end Then use Base.login('name','password') or Base.user = 'name' Base.pass = 'password' Base.login And go from there. Hope I understood the intent of your code correctly. T. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
More elegant replacement for global variables
Top