From: Andrew Johnson Date: 2004-02-19T02:15:04+09:00 Subject: Re: how to raise warning? On Wed, 18 Feb 2004 16:35:29 +0100, Szymon Drejewicz wrote: > I need something like 'weak exception' raising. "warn 'message' " works like > "puts 'message'", but I'd like to have line number like I have when I raise > exception. > The Kernel#caller method gives you the trace information. So you can redefine Kernel#warn along these lines: module Kernel alias :oldwarn :warn def warn(msg="", fulltrace=nil) trace = caller(1) where = trace[0].sub(/:in.*/,'') $stderr.puts "#{where}: Warning: #{msg}" $stderr.puts trace.map {|t| "\tfrom #{t}"} if fulltrace end end regards, andrew