From: "Ara.T.Howard" Date: 2004-02-17T00:34:55+09:00 Subject: Re: accessing constants from class methods On Mon, 16 Feb 2004, daz wrote: > Date: Mon, 16 Feb 2004 06:55:25 -0000 > From: daz > Newsgroups: comp.lang.ruby > Subject: Re: accessing constants from class methods > > > > David A. Black wrote: > > > > >OK, it's probably something simple but I'm staring and staring at the > > >original code, and its output (which is the same as daz's code), and I > > >can't figure out why it wasn't OK. > > > > > >Explanations welcome :-) > > > > > > > Your post didn't get through to the NG, David. > Ara probably didn't see it and there appeared to be no replies > when I posted. > > http://groups.google.com/groups?hl=en&th=5677a0c1234ad853 yes exactly - sorry david. > I'm wary about the defined? keyword -- I can't find a good > definition of what service it provides. > > for i in 0..1 # (avoiding new scope) > puts defined? a > a = 1 > puts defined? a > puts '-' * 10 > end > > #-> nil > #-> local-variable > #-> ---------- > #-> nil > #-> local-variable > #-> ---------- > > ## Strangely, for constants it works differently. > > for i in 0..1 > puts defined? X > X = 1 > puts defined? X > puts '-' * 10 > end > > #-> nil > #-> constant > #-> ---------- > #-> constant > #-> constant > #-> ---------- > > ## The next test made me wonder if I can believe anything, any more. > > for i in 0..1 > puts defined? Z > const_set Z, 1 > puts defined? Z > puts '-' * 10 > end > > #-> nil > #-> C:/TEMP/rb3273.TMP:17: uninitialized constant Z (NameError) > #-> from C:/TEMP/rb3273.TMP:15:in `each' > #-> from C:/TEMP/rb3273.TMP:15 THIS is the error i was getting but couldn't seem to reproduce it in response to an offline question from david. now i see that i could have done something very subtle to (re)create the bug... thanks for the warning - i will be catious when using 'defined?' in the future. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | URL :: http://www.ngdc.noaa.gov/stp/ | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done ===============================================================================