From: Pit Capitain Date: 2008-02-26T17:31:31+09:00 Subject: Re: Monkeypatching is Destroying Ruby 2008/2/25, Clifford Heath : > Phlip wrote: > > I want .inspect, or whatever, outside my module, to behave normally. But if > > you inspect a string while my module is above you on the call stack, I get > > my hotwired version of .inspect. > > Does anyone have a Ruby Hack which does that yet? How hard would it be? > > It can't be done in Ruby. (...) I would be *very* careful with sentences like this. Remember, this is Ruby. This topic has been discussed more than once on the mailing list. For example look at ruby-talk:244014. Here's the example Phlip talks about: require "import-module-extended" module MyModule extending(String) do def inspect return 'shock the monkey' end end def call_show(str) show(str) end end class MyClassA def call_show(str) show(str) end def show(str) p str end end class MyClassB include MyModule def show(str) p str end end MyClassA.new.call_show("hi") # => "hi" MyClassB.new.call_show("hi") # => shock the monkey Regards, Pit PS: I can't find Phlip's posts in the ruby-talk archives...