From: Clifford Heath Date: 2007-01-31T15:55:09+09:00 Subject: Re: Tricks with method as superclass Max Muermann wrote: > This is really cool. Thanks, I agree. Ara beat you to it, but I thought I'd post a simpler example too. The cute thing about this is that you can use method_missing magic to make the attached block use a different DSL than the class body. $ cat superclass-method-simple.rb class Foo def initialize(*args) puts "Initializing a Foo" end end def Foo(*args, &block) Class.new(Foo).class_eval <<-END @@_args = args @@_block = block def initialize super puts @@_args.inspect @@_block.call if @@_block end self END end class Bar < Foo("Hi there!") { puts "Surprise!" } end puts "All ready, here goes:" Bar.new $ ruby superclass-method-simple.rb All ready, here goes: Initializing a Foo ["Hi there!"] Surprise! $ Cute, huh? :-)