# Monkey-patching const\_missing and friends

**URL:** <https://www.ruby-forum.com/t/monkey-patching-const-missing-and-friends/68818>\
**Category:** Ruby\
**Created:** [September 15, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/monkey-patching-const-missing-and-friends/68818 "2006-09-15T18:06:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [September 15, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/monkey-patching-const-missing-and-friends/68818/1 "2006-09-15T18:06:55Z")

</div>

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 🙂
2. How would I re-run my core.rb file? Would I read it in and then eval  
it?

Thanks  
-John

> **[John Lam's Blog](https://www.iunknown.com/)**
>
> Since 1997

(Contact me off-list via removed\_email\_address@domain.invalid)
