From: Michael Garriss Date: 2003-09-14T14:54:12+09:00 Subject: Re: Dot versus double-colon 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. Michael