From: furtive.clown@... Date: 2008-02-29T02:49:59+09:00 Subject: Re: Proposed Solutions - Was [ Re: Monkeypatching is Destroying Ruby ] Topmost-level code could set up callbacks before the 'require' lines for the needed libs. It would be the client's responsibility to check for changes and adapt to them. SingletonListener.new(Array) { |singleton| singleton # => Array { :reopened_begin => lambda { # Encountered 'class Array' line ... probably only useful for thread sync # ... }, :reopened_end => lambda { # Encountered corresponding 'end' for the above 'class Array' # ... }, :method_added_begin => lambda { |method_name| # Someone has begun adding a method, either with the line # 'def foo' or define_method or otherwise method_name # => String # ... }, :method_added => lambda { |method| # Forwarded from Module's method_added method.class # => UnboundMethod }, :method_removed => lambda { |method| # Forwarded from Module's method_removed # ... }, :const_added => lambda { |const_name, value| # ... }, :const_removed => lambda { |const_name, value| # ... }, # ... other callbacks ... } } For example I plan to define Array#foo, but I get a callback from the library when it defines foo. After I've 'require'd everything I need, but before I've required my libs, I could run a unit test on the existing foo. If the results are identical to the test results of my implementation, I'd perhaps leave it alone. If not, then at least I know. This could all be done without SingletonListener, but the idea is to have a common idiom which people recognize and expect (if not SingletonListener then something else). --FC