[SOLUTION][QUIZ] QA Prototype (#91)

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 = 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 = Array.new
    begin
      line = gets
      method << line
    end until line.eql?("\n")
    @@methods[name]=method
    self.class.instance_eval do
      define_method(name) { eval(method.join) }
    end
    puts "OK"
  end
  
  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
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.
The views contained in this e-mail are those of the author and not
necessarily those of Admenta UK Group.
************************************************************************

Is that a typo? Should be "end" I assume.

James Edward Gray II

···

On Aug 22, 2006, at 3:52 AM, Lock Stephen wrote:

End