On 8/20/07, Daniel Berger <djberg96 / gmail.com> wrote:
> On Aug 20, 8:42 am, Daniel DeLorme <dan... / dan42.com> wrote:
> > Daniel Berger wrote:
> > > In environments where I have multiple Ruby installations, where some use
> > > rubygems and some don't, I do this:
> >
> > > require 'rubygems' rescue nil
> > > require 'funit'
> >
> > Er, that can't possibly work since LoadError isn't a subclass of
> > StandardError
>
> Yeah, yeah, it should have been "rescue LoadError nil".
>

I've found this little snippet to be useful for loading other people's gems ...

begin
  require 'funit'
rescue LoadError
  require 'rubygems'
  raise unless gem 'funit'
  retry
end

When I want to load code from my own gem ...

begin
  require 'my_stuff'
rescue LoadError
  path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
  raise if $:.include? path
  $: << path
  retry
end

I would put something like that in an executable Ruby script found in
the bin/ directory of my package.  It also works for test files, etc.

Blessings,
TwP



Blessings,
TwP