From: Luca Scaljery Date: 2008-06-23T05:56:04+09:00 Subject: extending a class Hi All I'm trying to add methods to a class like: class Person def refresh p "refresh" end def dup P "DUP" end TIMED_M = [:refresh, :dup] TIMED_M.each do |method| p method alias_method :"#{method}_without_timing", method define_method :"{#method}_with_timing" do p "timing" start_time = Time.now.to_f returning(self.send(:"#{method}_without_timing")) do end_time = Time.now.to_f puts "#{method}: #{"%.3f" % (end_time - start_time)} s." end end end end class << Person def start_trace TIMED_M.each do |method| p "x" alias_method method, :"#{method}_with_timing" end end end p = Person.new p.refresh Person.start_trace p.refresh For some unknown reason I get the following error: :refresh :dup "refresh" ./t2.rb:31:in `start_trace': uninitialized constant Class::TIMED_METHODS (NameError) from ./t2.rb:39 Any suggestions why I get this error ? thnx a lot LuCa -- Posted via http://www.ruby-forum.com/.