Ruby: Allowing a module to have settings

Posted by JP on Stack Overflow See other posts from Stack Overflow or by JP
Published on 2010-06-07T11:58:36Z Indexed on 2010/06/07 12:02 UTC
Read the original article Hit count: 165

Filed under:
|

If I'm building a library in ruby, what's the best way to allow users of the library to set module-wide settings that will be available to all sub classes etc of the library?

A good example would be if I'm writing a library for posting to a webservice:

TheService::File.upload("myfile.txt") # Uploads anonymously

TheService::Settings.login("myuser","mypass") # Or any other similar way of doing this
TheService::File.upload("myfile.txt") # Uploads as 'myuser'

The idea would be that unless TheService::Settings.logout is called then all TheService operations would be conducted under myuser's account.

Any ideas?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about modules