koboi wrote:
> I would like to redefine the method Kernel#rand inside a test method, and
> reset it in the end again.
> But everything I try fails. If I redefine it outside my module and class,
> it works. But I would like to do it inside my test method.
> 

def meth
    m = proc { 5 }
    Kernel.module_eval( "alias :rand_old :rand" )
    Kernel.module_eval( "def rand; #{m.call}; end" )
    puts rand
    Kernel.module_eval( "alias :rand :rand_old" )
    Kernel.module_eval( "remove_method( :rand_old ) " )
end

meth
puts rand

I hope this moves you in the right direction,

Zach