From: Gavin Sinclair Date: 2004-10-07T22:08:59+09:00 Subject: Re: quality of error messages On Thursday, October 7, 2004, 8:29:18 PM, Brian wrote: > On Thu, Oct 07, 2004 at 06:18:35PM +0900, Gavin Sinclair wrote: >> > Being forced to write that could be annoying too. But actually, just having >> > a way to test at compile time whether you're outside a method call, or >> > outside a class definition, would be good enough for me: >> >> > class Foo >> > def m1 >> > "foo" >> > end >> > method_boundary <-- raise error if inside 'def' >> >> method_boundary := "raise unless self == Foo" >> >> or (more general) >> >> method_boundary := "raise unless Class === self" > That doesn't work, because if it occurs within a method definition, it > doesn't get executed; it just gets compiled as part of the method. > class Foo > def m1 > if 1 == 2 > puts "Bad" > end > raise unless Class === self # nothing happens > end Try puts 'foo' then. If it's in a class, it will print it. If it's in a method, it won't. Good enough for debugging? Gavin