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)
7 def Object.flet(bindings, &block)
10 bindings.each do |the_method, body|
11 old_methods[the_method] = method(the_method)
12 define_method(the_method, body)
18 bindings.each do |the_method, body|
19 define_method(the_method) { |*args| old_methods[the_method].call(*args) }
26 puts "foo" # should output "foo"
28 Object.flet(:puts => lambda { |str| print "#{str.reverse}\n" }) do
29 puts "foo" # should output "oof"
32 puts "foo" # should output "foo"