On Mon, Oct 15, 2007 at 7:52 PM, Drew O. [email protected] wrote:
if this makes sense/how this could be improved.
super
old_teardown
end
end
end
Not a general solution:
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
class FunkedUpTester < Tester
include Stuff
def setup
puts “old setup”
end
def teardown
puts “old teardown”
end
end
p = PlainTester.new
e = ExtraFunTester.new
f = FunkedUpTester.new
puts “p.setup”
p.setup
p.teardown
puts “e.setup”
e.setup
e.teardown
puts “f.setup”
f.setup
f.teardown
RubyMate r8136 running Ruby r1.8.6
(/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby)
untitled
p.setup
plain setup
plain teardown
e.setup
old setup
old teardown
f.setup
SystemStackError: stack level too deep
method setup in untitled document at line 13
method old_setup in untitled document at line 13
method setup in untitled document at line 13
method old_setup in untitled document at line 13
method setup in untitled document at line 13
method old_setup in untitled document at line 13
method setup in untitled document at line 13
,
.
.
method old_setup in untitled document at line 13
method setup in untitled document at line 13
at top level in untitled document at line 78
–
Rick DeNatale
My blog on Ruby
http://talklikeaduck.denhaven2.com/