From: Lock Stephen Date: 2006-08-22T17:52:38+09:00 Subject: [SOLUTION][QUIZ] QA Prototype (#91) ------_=_NextPart_001_01C6C5C8.3B952874 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable My attempt - surprisingly short. Really annoying to test because every time you have a typo on a method name it offers to dynamically create the method for you! I imagine it's nothing too far removed from how everybody else is doing it. module QAPrototype @@methods =3D Hash.new def method_missing( name, *args ) puts "Undefined method " + self.class.to_s + "." + name.to_s puts "How do you want me to handle this method? (end with a newline)" $stdout.flush method =3D Array.new begin line =3D gets method << line end until line.eql?("\n") @@methods[name]=3Dmethod self.class.instance_eval do define_method(name) { eval(method.join) } end puts "OK" end =09 def print_defined_methods @@methods.each_pair { |key, value| puts key.to_s + ":" puts value } end End I found an interesting thing when trying this in the runtime in SciTE - for some reason when 'gets' reads in a line, if you made a mistake whilst typing and backspaced to delete some text and re-write it, then the string that 'gets' returns includes the deleted text. Anyone know why this might be? Stephen ************************************************************************ DISCLAIMER The information contained in this e-mail is confidential and is intended for the recipient only. If you have received it in error, please notify us immediately by reply=20 e-mail and then delete it from your system. Please do not copy it or use it for any other purposes, or disclose the content of the e-mail to any other person or store or copy the information in any medium.=20 The views contained in this e-mail are those of the author and not=20 necessarily those of Admenta UK Group. ************************************************************************ ------_=_NextPart_001_01C6C5C8.3B952874--