matt neuburg <matt / tidbits.com> wrote:

> Okay, scratch that. It's fatally flawed. Oh, well. m.

Aha! This is better:

###

class BigGuy
  def setup
    @favorites = "bluto"
  end
  def initialize
    setup
    p @favorites
  end
  class MiddleGuy < BigGuy
  end
  def self.make_subclass(what)
    p = Proc.new {@favorites = what}
    MiddleGuy.send( :define_method, :setup, p )
    return MiddleGuy.clone
  end
end

class LittleGuy < BigGuy.make_subclass('popeye')
end
class DevilishGuy < BigGuy.make_subclass(666)
end

BigGuy.new #=> "bluto"
LittleGuy.new #=> "popeye"
BigGuy.new #=> "bluto"
DevilishGuy.new #=> 666
LittleGuy.new #=> "popeye"

###

The Proc handles the problem with eval that I was having before, so any
kind of value can now be passed to make_subclass. The other problem I
was having is that we if called make_subclass twice with different
values, only one of those values was being used; hence the "clone" call.

Perhaps this will give the OP something to build on... Anyway it was fun
to think about.

m.
-- 
matt neuburg, phd = matt / tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com