tags:

views:

31

answers:

1

Hi,

I am able to debug my ruby program. At times, I would want to go inside the library methods and see what is happening. How to achieve it in Ruby.

For example,

[ 3, 1, 7, 0 ].sort

i would want to go inside the sort method and see how that works lively. In Java+Eclipse this is possible, all I have to do is to attach the source of Foundation classes in Eclipse. Is it possible in Ruby with Netbeans as IDE?

Thanks

+2  A: 

For those methods which are implemented in Ruby, the debugger will just step into them.

For those methods which are not implemented in Ruby, i.e. they are implemented in C in MRI, YARV and tinyrb, in Java in JRuby and XRuby, in C# in IronRuby and Ruby.NET, in Smalltalk in MagLev and SmallRuby, in ABAP in BlueRuby, in Go in RubyGoLightly, in C++ in Rubinius or in Objective-C in MacRuby, the NetBeans Ruby plugin contains a stub method that only lists the method signature and the RDoc comments, but not the actual implementation.

The NetBeans Ruby debugger is, after all, a Ruby debugger, it doesn't know how to step into C, C++, Objective-C, C#, Smalltalk, ABAP or Java.

It would probably be possible to somehow link together the Ruby debugger with, say, the C++ debugger (provided that you have installed the NetBeans C++ plugin), but nobody has done that work yet.

In your specific case, in almost all Ruby implementations, Array#sort is not implemented in Ruby. The only exception is probably Rubinius, but I don't know whether Rubinius is supported by the NetBeans Ruby plugin (I use Windows and Rubinius isn't supported on Windows).

Jörg W Mittag
Thanks for your detailed reply! I cannot quite understand by Array#sort not implemented in Ruby??? (pardon me, I am thinking everything equivalent to Java). Where can i find the implementation Array#sort. I mean, if i go inside the implementation in Netbeans, all I'm able to see is the stub as you've said. I wanted to know the logic of the sort method (whether its quick or merge).
Bragboy
Is ruby a language or a wrapper???
Bragboy
Some parts of the Ruby language are too low level to be represented using Ruby. Basically the entire base of the language is written in another language, and then the rest is written in Ruby building on that base. Matz, the creator of ruby used C++ to write that base. JRuby uses Java. That means that the debugger wouldn't be able to actually show you everything since at one point you run into another language, that it doesn't know how to step into. Edit: you can see the source of Array.sort by clicking the name of the method in this page http://ruby-doc.org/core/classes/Array.html#M002185
Andrei Fierbinteanu
@frosty: Got it.. Just one more question. How to know what language my Ruby program uses? (I just installed netbeans with ruby on windows platform)
Bragboy
@Bragaadeesh Most languages are implemented in something lower-level - everything's some degree of abstraction away from binary! The Windows versions of (MRI) Ruby are implemented in C, compiled either with MS C V6 (Ruby 1.8.6) or gcc (1.8.7 and 1.9+) If you type `ruby -v` at a command prompt, the version string should either contain "mswin32" (MS compiler) or "mingw32" (gcc) somewhere. IronRuby and JRuby would report the particular runtimes they reference. NetBeans runs the C or Java-based versions. I don't think it will debug into the Java parts when in Ruby mode, although I've never tried.
Mike Woodhouse
@Mike. Thanks, Yes I agree, if you split down further, i below lower-level we are talking about flip-flops which further split goes to chips and electrons' movement. :) Anyway, you just answered my specific question thats the ruby -v command.
Bragboy