On Sep 12, 2011, at 8:52 PM, Nick Klauer wrote:

> Is it possible to know whether a method, class, or instance was overridden
> by another when you require 'said_gem' in (i.e. monkeypatched)?  I'm
> thinking something that would let gem users know if a gem is going to
> override core methods or attrs?
> 
> I was thinking that alot of the time, we try out a gem hoping it will suit
> our needs, and ideally, you would probably want to look at the source code
> of the gem before using it in production.    However, if you were able to
> run some test or metric on a gem to find out what (if any) methods, classes,
> instances, attributes, etc., were being overwritten, and where they were
> being overwritten at, it might give you a better idea of potential problems
> down the road.
> 

One quick and dirty way to do this is to freeze all your classes before including a gem. Obviously you would never deploy code that does this, but you most certainly can try things out in a local IRB session.

In fact, I tinkered around with this a while ago and came up with the never released "monkey_proof" library.

https://gist.github.com/1213116


  require 'monkey_proof'

  monkey_proof Object
  monkey_proof Array
  monkey_proof Hash
  monkey_proof Fixnum

  require 'active_support/all'

  #=> RuntimeError: can't modify frozen class


Very heavy handed, but it will tell you if someone is monkeying about with your classes.

Blessings,