From: Drew Olson Date: 2007-10-16T08:52:17+09:00 Subject: Re: Override methods from a module Drew Olson wrote: > Your examples definitely help and may have helped me with another way of > looking at the problem but I'm not sure they'll work as my objects are > already extending parent objects. > > - Drew Sorry about the previous response. Apparently lack of sleep results in horrendous grammar. Below is the solution I've figured out for the problem. It seems to work the way I was hoping for. Please let me know if this makes sense/how this could be improved. Thanks, Drew module Stuff def self.included mod @@mixer_class = mod end def initialize super @@mixer_class.class_eval do alias_method :old_setup, :setup alias_method :old_teardown, :teardown define_method(:setup) do old_setup puts "new setup" end define_method(:teardown) do old_teardown puts "new teardown" end end end end class Tester def common puts "this is in all tests!" end end class PlainTester < Tester def setup puts "plain setup" end def teardown puts "plain teardown" end end class ExtraFunTester < Tester include Stuff def setup puts "old setup" end def teardown puts "old teardown" end end p = PlainTester.new e = ExtraFunTester.new p.setup p.teardown e.setup e.teardown -- Posted via http://www.ruby-forum.com/.