# QAPrototype (#91)

**URL:** <https://www.ruby-forum.com/t/qaprototype-91/66036>\
**Category:** Ruby\
**Created:** [August 22, 2006, 10:53pm UTC](https://www.ruby-forum.com/t/qaprototype-91/66036 "2006-08-22T22:53:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![erikveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/59ef9b/32.png) [@erikveen](https://www.ruby-forum.com/u/erikveen)\
**Post date:** [August 22, 2006, 10:53pm UTC](https://www.ruby-forum.com/t/qaprototype-91/66036/1 "2006-08-22T22:53:52Z")

</div>

* * *

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

"#\<Foo:0xb7d7ebfc @x=7, @z=-605293058, @y=8\> "  
"#\<Foo:0xb7d7e954 @x=7, @z=-605293398, @y=8\> "

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/](http://www.erikveen.dds.nl/)
