On 5/3/06, James Edward Gray II <james / grayproductions.net> wrote:
> I'm pretty confident the order Ruby loads code is a well defined process.
> Please show us some sample code.

I think the core of what David is talking about comes down to this point:

  $ cat foo.rb
  class Foo
    def quux
      "This is one definition"
    end
  end

  $ cat bar.rb
  class Foo
    def quux
      "This is another definition"
    end
  end

  $ cat baz1.rb
  require 'foo'
  require 'bar'
  puts Foo.new.quux

  $ cat baz2.rb
  require 'bar'
  require 'foo'
  puts Foo.new.quux

  $ ruby baz1.rb
  This is another definition

  $ ruby baz2.rb
  This is one definition

So the execution of the code ("the code" being to everything excepting
the require statements) is dependent on the ordering of the require
statements.

In a simple case like this, it's easy to say "just make sure you
require them in the right order". But, guessing from David's
description, webrick and fastcgi are doing their own requiring --
Instiki is not doing the requiring, and David's code is not doing the
requiring -- in different orders which is causing this problem.

This just reiterates the need for two libraries be *very careful*
about extending any code from foreign libraries. Otherwise, you get
people stomping on each others feet.

So I agree with David about his analysis of the situation -- this
shouldn't be happening. It's not his fault, and it might not even be
instiki's fault (don't know).

I disagree however with the solution. I don't think that this is a
fault of Ruby for allowing this toe stomping, but of the authors of
the libraries that aren't playing nicely together. If you are going to
release a module as a library and that module plays with the internals
of other modules, be *very careful* and *document*! And even if you
think you're only "extending" a module by adding a method not in the
module's original implementation, assume you're actually replacing an
existing method and act accordingly -- you don't know when someone
else, including the author him/herself in a future version, might also
want to use that method name.

Jacob Fugal