From: Erik Veenstra Date: 2006-08-23T05:52:48+09:00 Subject: [Solution] QAPrototype (#91) ---------------------------------------------------------------- module QAPrototype def method_missing(method_name) puts "#{method_name} is undefined" puts "Please define what I should do (end with a newline):" (code ||= "") << (line = gets) until line and line.chomp.empty? self.class.module_eval do define_method(method_name){eval code} end at_exit do puts "" puts "class #{self.class}" puts " def #{method_name}" code.gsub(/[\r\n]+$/, "").split(/\r*\n/).each{|s| puts " "*4+s} puts " end" puts "end" end end end ---------------------------------------------------------------- class Foo include QAPrototype end 3.times do foo = Foo.new foo.bar foo.baz end ---------------------------------------------------------------- $ ruby test.rb bar is undefined Please define what I should do (end with a newline): @x = 7 @y = 8 @z = self.object_id baz is undefined Please define what I should do (end with a newline): p inspect "# " "# " class Foo def baz p inspect end end class Foo def bar @x = 7 @y = 8 @z = self.object_id end end ---------------------------------------------------------------- gegroet, Erik V. - http://www.erikveen.dds.nl/