Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2338

Seeking advice

From Alex Rothbard <alex323@gmail.com>
Newsgroups comp.lang.ruby
Subject Seeking advice
Date 2011-04-05 08:22 -0500
Organization Service de news de lacave.net
Message-ID <a5c155d833135cc1cccec3cf894380c8@ruby-forum.com> (permalink)

Show all headers | View raw


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/.

Back to comp.lang.ruby | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Seeking advice Alex Rothbard <alex323@gmail.com> - 2011-04-05 08:22 -0500
  Re: Seeking advice Robert Klemme <shortcutter@googlemail.com> - 2011-04-05 08:39 -0500
    Re: Seeking advice Johnny Morrice <spoon@killersmurf.com> - 2011-04-05 09:44 -0500
      Re: Seeking advice Robert Klemme <shortcutter@googlemail.com> - 2011-04-05 10:23 -0500
  Re: Seeking advice Johnny Morrice <spoon@killersmurf.com> - 2011-04-05 08:43 -0500
  Re: Seeking advice Alex Rothbard <alex323@gmail.com> - 2011-04-05 13:30 -0500
    Re: Seeking advice Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-06 01:53 -0500
    Re: Seeking advice Robert Klemme <shortcutter@googlemail.com> - 2011-04-06 04:30 -0500

csiph-web