Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
[Solution] QAPrototype (#91
Erik Veenstra
8/22/2006 8:53:00 PM
----------------------------------------------------------------
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.erikve...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
[Solution] QAPrototype (#91
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password