2 # Horribly disregard any OOP best practices by temporarily redefining
3 # methods for the duration of a block. Stolen from Common Lisp.
5 # DON'T USE THIS! (unless your *really* mean it and there's no other way)
8 def flet(bindings) # :nodoc:all
11 bindings.each do |the_method, body|
12 old_methods[the_method] = method(the_method)
13 define_method(the_method, body)
19 bindings.each do |the_method, body|
20 define_method(the_method) { |*args| old_methods[the_method].call(*args) }
28 puts "foo" # should output "foo"
30 Object.flet(:puts => lambda { |str| print "#{str.reverse}\n" }) do
31 puts "foo" # should output "oof"
34 puts "foo" # should output "foo"