Monkey-patching const_missing and friends

In RubyCLR, I currently have a baseline dependency on ActiveRecord
because I need to patch const_missing after ActiveRecord does.So in
my top rubyclr.rb file it looks something like:

require ‘rubygems’
require_gem ‘ActiveRecord’

… lots of other requires for RubyCLR stuff.

require ‘databinding’

Now, RubyCLR core doesn’t have a dependency on databinding, only the
databinding ‘extensions’ do. I’d only like to drag in the dependency
on ActiveRecord when a user needs the databinding extensions, so I’d
like their program to look like:

require ‘rubyclr’
require ‘databinding’

to explicitly state their intent.

However, if I require ActiveRecord in the databinding module, it wipes
out my monkey patching of const_missing and friends (they’re not
delegating properly, at least on the 1.3.1 local build that I have on
my dev box). The offending line of code is in dependencies.rb:123:

  raise NameError.new("uninitialized constant 

#{class_id}").copy_blame!(e)

They instead should be delegating to rails_original_const_missing
instead.

Now, this isn’t really the issue here - I’ll report this bug through
the normal channels. Instead, it raises the larger issue of how to
co-exist with other libraries who might be doing ‘bad’ things like
this.

I think I’d like to re-run my core.rb file that monkey patches
everything after the offending library. My questions are:

  1. Is this a good idea at all? (workarounds would be appreciated :slight_smile:
  2. How would I re-run my core.rb file? Would I read it in and then eval
    it?

Thanks
-John

(Contact me off-list via [email protected])