Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail From: Alex Rothbard Newsgroups: comp.lang.ruby Subject: Seeking advice Date: Tue, 5 Apr 2011 08:22:17 -0500 Organization: Service de news de lacave.net Lines: 28 Message-ID: NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1302009771 32653 65.111.164.187 (5 Apr 2011 13:22:51 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Tue, 5 Apr 2011 13:22:51 +0000 (UTC) X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 380997 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:2338 Hi. I am writing a library that will have the ability to access a server by many different "transports" (JSON over HTTP, Thrift, etc). Depending on which transport the user chooses, different files and classes will need to be loaded. A complete implementation of a transport requires that three classes (such as the 'Grid' class below) be implemented from their respective base class. Additionally, if the user wants to use JSON over HTTP, they shouldn't need to depend on the thrift gem and vice versa. These transport classes are used by other classes within the library, and should never be used directly by the user. What is the best way to allow the user of the library to specify a transport at runtime? Could I wrap all my implemented transport classes in a module and do something like this?: def initialize(transport) @t = transport @grid = @t::Grid.new end where "transport" could be "MyProject::Transport::Thrift". Is this a good idea? Is there a better way? -- Posted via http://www.ruby-forum.com/.