3 Ruby Tools For Newbies

If you're new to programming in Ruby, here are the 3 tools you must know.

The Ruby debugging tool can be found in the library file debug.rb. This tool will let you run your program one instruction at a time, with pauses in between. At every pause you can examine the values or variables of your code, locate your position in a series of nested commands and/or resume execution. You can also tell the debugger when to stop, more commonly known as breakpoints.

Using a debugger varies from programmer to programmer. Just because a debugging facility is available for Ruby, it doesn't mean that a novice programmer should quickly adapt himself to using it at once. There are programmers who are comfortable using a debugger, some aren't. It's a matter of preference but at any rate, it's nice to know that there's a tool available for Ruby.

Eventually, when you start writing longer programs, you'll want to measure how much resources, especially time, is used up by parts of your program or as a whole. This is called profiling.

You can do profiling using the command $ ruby -r profile myfile.rb
Profiling identifies the areas in your program that are using up lots of the system resources. Having identified these areas, you need to re-code your program to make it run efficiently.

Probably the coolest tool of them all, Ruby provides you with a program called ERb (Embedded Ruby), which allows you to put Ruby code inside an HTML file. You get to embed Ruby inside non-Ruby, and interprets the whole thing as program input.


Popular posts from this blog

Interview Question on Ruby on Rails

Inserting and Moving elements inside Ruby Array