From: Hal Fulton Date: 2003-09-14T14:59:03+09:00 Subject: Re: Dot versus double-colon Michael Garriss wrote: > Hal Fulton wrote: > >> Michael Garriss wrote: >> >>> Michael Garriss wrote: >>> >>>> Hal Fulton wrote: >>>> >>>>> Even though it looks almost like recursion. Hmm, that raises >>>>> the question of why/how this works. >>>>> >>>>> And another issue is: One *could* write a little module that, >>>>> when included in a class, exposed all the class's constants in >>>>> this way. Within five minutes I had it "almost" working. I'll >>>>> bet someone in another timezone or with more caffeine could >>>>> have it working in three. Anyone? >>>>> >>>>> Hal >>>> >>>> >>>> >>>> >>>> >>>> >>>> module Dot >>>> def Dot.append_features( mod ) >>>> mod.constants.each{|c| mod.class_eval( "def self.#{c}() >>>> #{mod}::#{c} end" ) } >>>> end >>>> end >>>> >>> >>> Has to be included after all consts are defined......working on >>> that...... >> >> >> >> constant_added might help. and fyi, I was trying to use >> define_method rather than eval'ing a string. wonder if >> the techniques are interchangeable? >> > > Not sure. For some reason I never use #define_method. I tend to get a > little #eval happy sometimes. It was just so exicting when I learned > about #eval that I have trouble putting it down. I'll have to add > #define_method (and #constant_added for that matter) to my bag 'o tricks. I think I meant constant_missing. Hmm, *is* there a constant_added??? If not, maybe there should be. But constant_missing might not be useful here. My brain is *really* getting cloudy now. I'm the same way. I've overused eval in the past (by some people's standards). But now we've got const_[gs]et, instance_variable_[gs]et, define_method, and all that coolness. These often obviate the need for eval. Hal