Skip to main content

Using IRB in NetBeans

Posted by bleonard on March 23, 2007 at 11:17 AM PDT

I've been playing around with the IRB (Interactive Ruby Shell) Console in NetBeans. Generally, IRB is started from the command prompt in the directory containing your scripts. However, in NetBeans, it's launched from the NetBeans installation directory. So here are some tips on using IRB in NetBeans.

  1. Create a Ruby Application named IRBTest.
  2. In main.rb, define the following Blog class which we'll use for testing:

  3. From the Window menu, select IRB - Interactive Ruby Shell:

  4. The console will open in the editor's Output pane:

  5. Check your version of Ruby:

  6. Try to create a new Blog:

  7. The main.rb script file needs to be loaded into IRB first.

  8. Enter Dir.pwd

  9. Change to your project's lib directory:

  10. Try loading main.rb again:

  11. And now we can work with it:

  12. Add a body attribute to the class as follows:

  13. The try to set the body attribute:

  14. The script just needs to be reloaded and then you can use the up arrow to rerun the blog.body command:

  15. Closing the IRB window does not terminate your session (which is a good thing). To terminate your IRB session, type quit or exit.
Related Topics >>