On Sun, 20 Aug 2006, Luke Kanies wrote:

> Hi all,
>
> I finally wrote up how I'm dynamically generating classes (and why), and I
> thought some of you might enjoy it:
>
> http://madstop.com/articles/2006/08/19/my-ruby-metaprogramming
>
> The article discusses a new method I've created in Puppet for making dynamic
> class creation easier, and in the process discusses why I do this a lot and
> some future directions for more abstraction.
>
> Comments and suggestions appreciated.

first off, thanks for the article - i know this stuff is hard to write
about...

few questions/comments:


- Why I dynamically generate

   can you give a little more context for the code shown:

     package { ssh: ensure => installed, type => apt }

   is this statement part of a dsl?


- Avoiding the inherited method

   have you used delayed initialization like so:

     harp:~ > cat a.rb
     class Base
       @subs = Hash.new{|h,sub| Base.name2subs[sub].post_inherited}
       @name2subs = Hash.new

       class << self
         attr_accessor :subs
         attr_accessor :name2subs
       end

       def self.inherited sub
         Base.name2subs[sub.name] = sub
       end

       def self.post_inherited
         Base.subs[name] = self
       end
     end

     class Sub < Base
     end

     p Base.subs['Sub']
     p Base.subs


     harp:~ > ruby a.rb
     Sub
     {"Sub"=>Sub}

   i'm curious because i've faced this issue many times before too...



- i'm curious if the generated objects really need to be classes?  what i mean
   is are there instances created later?  the reason i ask is that i've been
   playing with prototypes lately and wondering if that might be applicable to
   this kind of problem

     http://www.codeforpeople.com/lib/ruby/prototype/prototype-0.2.0/README


interesting stuff.

cheers.


-a
-- 
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dali lama