The Source for Java Technology Collaboration
User: Password:



Brian Leonard

Brian Leonard's Blog

Using IRB in NetBeans

Posted by bleonard on March 23, 2007 at 11:17 AM | Comments (5)

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.

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • How about a title for this entry?

    Posted by: kirillcool on March 23, 2007 at 11:29 AM

  • Brian,

    I went to use the IRB shell in Netbeans. I created a model that I tried to load and get the following error.

    irb(main):001:0> Dir.chdir('D://Creator//Projects//photo')
    => 0

    irb(main):002:0> load 'app//models//photo.rb'
    NameError: uninitialized constant ActiveRecord
    from app//models//photo.rb:2:in `const_missing'
    from app//models//photo.rb:2
    from (irb):1:in `load'
    from (irb):1:in `binding'

    It seems that IRB doesnt understand what the ActiveRecord class is. The class looks like the following

    class Photo ActiveRecord::Base
    end

    any help would be great.

    Posted by: pdimarco on May 23, 2007 at 01:39 PM

  • Yes, for ActiveRecord you need the Rails Console, which unfortunately does not yet work in NetBeans (issue 97594).

    Posted by: bleonard on May 24, 2007 at 07:01 AM

  • When I configure Netbeans to use native Ruby instead of JRuby. Why does Netbeans continue to use the IRB that comes with JRuby?

    Posted by: co11983 on December 04, 2007 at 05:59 PM

  • Because the NetBeans IRB shell is Swing component that provides a lot of nice features like tab completion that you do not get with the native IRB shell. Check this FAQ, How can I run IRB with native Ruby, for more information and a flag you can set to get a native shell.

    Posted by: bleonard on December 05, 2007 at 11:40 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds