From: Michal Kwiatkowski Date: 2006-12-24T12:25:05+09:00 Subject: Re: Reverting module changes Mat Schaffer wrote: > On 12/23/06, Michal Kwiatkowski wrote: > > I want to mock standard Kernel.system with my own method and then > > revert back to the original version. I was able to do the former, but > > not the latter. Currently I'm overwriting Kernel.system method > > definition with: > > > > def system_should_return what > > Kernel.module_eval "def system(*args) #{what.inspect} end" > > end > > > > I don't a have idea how going back to the original state can be done. > > Thanks in advance for any help on this. > > Maybe there's something more elegant. But I'd first alias the > original method, redefine it, then when I was done, I'd redefine it > again to just call the alias. Thanks, aliasing was what I was looking for. Does code below look OK or can be improved? def system_should_return what Kernel.module_eval <<-EOV alias_method :orig_system, :system def system(*args) #{what.inspect} end EOV end def restore_system_behaviour Kernel.module_eval <<-EOV def system() orig_system end EOV end Cheers, mk