From: Chris Cummer Date: 2007-12-20T12:04:08+09:00 Subject: Re: Monkey patching a private method? On 19-Dec-07, at 11:43 AM, Wes Gamble wrote: > I have found an issue with a method in a library that I'm using. I > would like to modify this method via a monkey patch, but it is a > private > method, and I'm not seeming to get my patch to work. > > Can the following be done? Assume a private method "meth" in class > Mod::Kls. > > module Mod > class Kls > private > def meth(arg1) > @stuff = things > end > end > end > > Thanks, > Wes If I understand correctly what you're intending, you can sort'a get around it via the following technique in which the public priv_meth() over-rides the private one. This is not ideal though since it leaves priv_meth() public. Is this what you're thinking? class TestClass def pub_meth return priv_meth() end private def priv_meth return "cat" end end #=begin class TestClass def priv_meth return "dog" end end #=end a = TestClass.new puts a.pub_meth puts a.priv_meth