R
Ruby Quiz
The three rules of Ruby Quiz:
1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.
2. Support Ruby Quiz by submitting ideas as often as you can:
http://www.rubyquiz.com/
3. Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
by Caleb Tennis
I remember playing with some old AI programs of which you could ask questions
and if it didn't know the answer, it would ask you what the answer is:
Hi, I'm an AI program. What's your question?
I'm afraid I don't know the answer to that. Please tell me what I should say.
Okay, I will remember that. Please ask a question.
Just fine, thanks.
Please ask another question.
This got me thinking about an interesting concept in Ruby.
Your Quiz: Write a Ruby module that can be mixed into a class. The module does
the following: upon receiving a method call that is unknown to the class, have
Ruby inform the user that it doesn't know that particular method call. Then,
have it ask the user for Ruby code as input to use for that method call the next
time it is called.
Example:
some_unknown_method is undefined
Please define what I should do (end with a newline):
Okay, I got it.
"The value of foo is 5"
[Editor's Note:
I envision this could actually be handy for prototyping classes IRb. Bonus
points if you can later print the source for all methods interactively defined.
--JEG2]
1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.
2. Support Ruby Quiz by submitting ideas as often as you can:
http://www.rubyquiz.com/
3. Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
by Caleb Tennis
I remember playing with some old AI programs of which you could ask questions
and if it didn't know the answer, it would ask you what the answer is:
Hi, I'm an AI program. What's your question?
I'm afraid I don't know the answer to that. Please tell me what I should say.
Okay, I will remember that. Please ask a question.
Just fine, thanks.
Please ask another question.
This got me thinking about an interesting concept in Ruby.
Your Quiz: Write a Ruby module that can be mixed into a class. The module does
the following: upon receiving a method call that is unknown to the class, have
Ruby inform the user that it doesn't know that particular method call. Then,
have it ask the user for Ruby code as input to use for that method call the next
time it is called.
Example:
object.some_unknown_method
some_unknown_method is undefined
Please define what I should do (end with a newline):
Okay, I got it.
"The value of foo is 5"
[Editor's Note:
I envision this could actually be handy for prototyping classes IRb. Bonus
points if you can later print the source for all methods interactively defined.
--JEG2]