Ruby and Rails Interactive Consoles
In spite of the integrated ‘visual’ debugger, there are many times when it is useful to interact with your programs using a console. Ruby In Steel provides a number of interactive consoles - they can be used to do anything from evaluating a simple mathematical expression (1+2) to drilling down into complex objects. Here is a quick guide to the Ruby In Steel consoles...
The Ruby Console acts as an integrated ‘command prompt’. When you run a Ruby program that uses methods such as print, puts and gets to interact with the user, the input and output goes into the Ruby Console by default (i.e. when you press CTRL+F5 or F5 to run or debug). If you prefer to use the standard (non-docked) command prompt, you can use the CTRL+1 shortcut instead. Notice that, when paused at a breakpoint, you can mark and evaluate variables (such as @imp shown above) in the Ruby console and ‘drill down’ to inspect them.
The IRB (Interactive Ruby) console lets you interact directly with the Ruby interpreter to ‘try out’ and test bits of code. Once again, this window can be docked or ‘floated’.
The Rails console is a version of IRB which ‘knows about’ the currently running Rails applications. So if you have written custom classes, the Rails console lets you create new objects from them and try out various methods.
The script console loads when you run Rake or Generate scripts using Ruby In Steel’s script tools. Here for example, I am using the Generate tool to create a controller...
This fires up the Script console....
It informs me that a controller with the same name already exists and asks if I want to overwrite it. I can enter a response in the docked script window rather than having to run scripts at the system prompt.
The Immediate Window
The Immediate window is a Visual Studio ‘standard’. In Ruby In Steel, it can be used when you are debugging and stopped at a breakpoint. With Rails in particular it is a convenient alternative to the Ruby Console (which will typically contain server information when running Rails) for running bits of Ruby code. When you want to inspect complex objects, just mark them and hover your mouse to ‘drill down’ into them.
Hints For Using The Consoles
Scroll back and forward through your ‘command history’ using the up and down arrow keys.
Move quickly through commands (one word at a time) using CTRL+Left and CTRL+Right.
Right click and select ‘Clear All’ to clear the console.
Set the consoles to dock, float or tab (along with the editor windows) by right-clicking their caption bars.
Color the consoles as you wish (Tools/Options/Fonts and Colors: then select ‘Show Settings For: Immediate Window/IRB Console/Rails Console/Ruby Console/Script Console).