--nextPart6413066.WPbtAHqSN2
Content-Type: text/plain;
  charsetso-8859-6"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Well, here is my solution. I kind of surprised myself at how short it is, but 
then, there are many ways I could make this much better. The biggest problem 
is that it cannot deal with arguments to the methods. It uses a global to 
keep track of the interactively coded methods, I just couldn't get it to work 
any other way. I guess this is because modules/mixins are not supposed to 
have instance variables or keep track of their own state. The print_method 
function will break if your method is a one-liner. I know I could do some 
case-analysis to take care of this but I am a lazy, lazy man.

Here is a brief irb session demonstrating it, the code follows...
#########################################

> load 'quiz91.rb'
> class Test; include MethodMaker; end
> test = Test.new
> test.foobar()
No such method: foobar
Care to define foobar? (y/n) y
Enter method definition ([ctrl-d] when done):
first = "Ruby"
middle = "is teh"
last = "roXX0r"
puts "#{first} #{middle} #{last}"
<ctrl-d>
=> nil
> test.foobar()
Ruby is teh roXX0r
=> nil
> test.print_method("foobar")
def foobar
  first = "Ruby"
  middle = "is teh"
  last = "roXX0r"
  puts "#{first} #{middle} #{last}"
end
=> nil
> test.another_one()
No such method: another_one
Care to define another_one? (y/n) y
Enter method definition ([ctrl-d] when done):
a = 4
b = 5
c = 67
return a + b + c
<ctrl-d>
=> nil
> x = test.another_one()
=> 76
> x
=> 76
> test.print_method("another_one")
def another_one
  a = 4
  b = 5
  c = 67
  return a + b + c
end
> ...

#########################################

module MethodMaker
  $imethods = Hash.new

  def method_missing(method_name)
    puts "No such method: #{method_name}"
    # It might be a simple typo...
    # so give a chance to bail out.
    print "Care to define #{method_name}? (y/n) "
    if $stdin.getc == 121 # 'y'
      prompt_method(method_name)
    else
      raise NoMethodError, "#{method_name}"
    end
  end

  def prompt_method(name) 
    puts "Enter method definition ([ctrl-d] when done):"
    meth = "def #{name}"
    while $stdin.gets
      meth += $_
    end
    meth += "end"
    meth = meth.gsub("\n",";")
    $imethods["#{name}"] = meth
    eval meth
  end

  def print_method(name)
    meth_Array = $imethods[name].split(";")
    puts meth_Array[0]
    meth_Array[1..meth_Array.size-2].each { |line| puts "  #{line}" }
    puts meth_Array[-1]
  end
end

########################################

-d
-- 
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

--nextPart6413066.WPbtAHqSN2
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQBE6FavwPD5Cr/3CJgRAkW/AJ9uaPau/U/4fWBwe3d06kEc75ldZwCgohkh
Tot1mYMk6/pvq2K2+QkeYi0z5
-----END PGP SIGNATURE-----

--nextPart6413066.WPbtAHqSN2--