I’m looking to write a quiz application to help folks new to the Ruby language (such as myself) learn Ruby.
I’m interested in writing a program which will prompt the user with a question, start an Interactive Ruby Shell (IRB) session, set the preconditions, allow the user to interact with the shell, and then check the post conditions to see if the user followed the prompt and answered the question correctly. For example, the user could be prompted to combine two arrays containing days of the week. The shell session would be started, and the preconditions would be set:
days1 = ["Mon", "Tue", "Wed"]
days2 = ["Thu", "Fri", "Sat", "Sun"]
The user would then be able to interact with the shell, and would presumably do something like this:
days = days1 + days2
=> ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
The program would then evaluate the post conditions to verify that the two array had been combined. The program may also have to take a look at specifically how the task was accomplished, if the prompt specified that it must be accomplished in a particular way.
What’s the best way to handle the interaction with IRB? One idea would be to use Expect, but I was wondering if you had a better method or perhaps a method that only involved using Ruby. I’m not looking to reinvent the wheel, so if there is already a program like this available, I’m open to using that instead of doing custom development.
You might look at the alternative of irb, the pry. With pry your task is looked easier for me.
The only problem with it that the binding command automatically calls the whereami command which prints the surrounding context of the binding point. I don’t know yet how to cancel it. Fixed, thanks to banister.