From: Rich Kilmer Date: 2002-08-24T22:37:18+09:00 Subject: RE: equivalent of python's __debug__ > -----Original Message----- > From: David Garamond [mailto:davegaramond@icqmail.com] > Sent: Saturday, August 24, 2002 8:47 AM > To: ruby-talk ML > Subject: Re: equivalent of python's __debug__ > > ts wrote: > >>>>>>"D" == David Garamond writes: > >>>>> > > > > D> def foo(self, x, y): > > D> if __debug__: > > D> self.__doc__x = "...some longish string..." > > D> self.__doc__y = "...some also longish string..." > > D> self.__doc_spec1__ = "...yet another string..." > > D> ... > > D> ... > > > > Well, I've perhaps not understood but you can write (like previously > said) > > > > pigeon% ruby -e 'if $DEBUG; a = "a long string"; p a; end' > > pigeon% > > > > pigeon% ruby -de 'if $DEBUG; a = "a long string"; p a; end' > > "a long string" > > pigeon% > > but "a long string" still gets allocated by ruby. i want optimize _away_ > the debug portion, so ruby doesn't consider it exist at all. > Well, Ruby does parse and place those (long string) elements within the Abstract Syntax Tree of the interpreter, but they are not allocated during every call through a method, so the impact is lower. Remember that Ruby is interpreted so this minimization makes a difference. Another idiom I often use is: def foo $DEBUG && (puts "entered foo") ...other stuff... end Because it's a logical && if $DEBUG is negative the right hand statement will not be evaluated.