by http://webgeektutorials.blogspot.com

Friday, February 11, 2011

How well you know Interactive Ruby Shell?

The Interactive Ruby Shell, more commonly known as IRB, is one of Ruby's most popular features, especially with new developers. You can bash out a one-liner, try a method you've just learned about, or even build a small algorithm or two without going the whole way to writing a complete program.
I've started learning ruby, so while I've been digging through some of the best content I can find on IRB learning all about its internals and ways to get more out of it and big thanks to all of those guys who contributed great knowledge on web, thought I should share some of best contents gathered :

Try out some trick in your IRB console:

irb> Kernel.methods.each do |method| puts method; system "/usr/local/bin/ri --no-pager Kernel##{method}"; ch = STDIN.getc; break if (ch.chr == 'q') end

Once you enter this just keep hit enter until you want to quit, at that point hit ‘q’ and enter.


How to clear IRB console ?

On Mac OS X or Linux you can use Ctrl + L to clear the IRB screen. But in windows i don't know how but yes i know the dos command 'cls' which clears screen. so simply i'm calling this command using system.

irb> system('cls')


What's Your Favorite IRB Trick? - 1.A list of community-provided IRB tricks and tips on Stack Overflow. Of particular note is the first answer that covers the basic subsession commands (jobs, fg #, and kill #). There are also suggestions for easier benchmarking, predefined data, and using Wirble (mentioned below).

Utility Belt - A "grab-bag of tricks, tools, techniques, trifles, and toys for IRB." There's a ton of useful stuff in here for IRB power users and the feature list is longer than my arm: Amazon S3 support, "with" statement, history buffer, Pastie support, OS X clipboard support, external text editor support, auto-indentation, and more.

Demystifying Irb's Commands - An awesome look at the hidden internals, special methods and features within IRB and the impetus for starting this post. Author Gabriel Horner looks at stuff like workspaces, subsessions, and IRB-specific loading methods.


irb & script/console tips - A few useful IRB tips and resources from Thoughtbot's Dan Croak. Very practical and code driven. Dan advises loading pp (pretty printer) by default from your .irbrc file.

irb_rocket: An irb plugin - irb_rocket is an add-on for IRB that presents the result of your expression at the end of the current line in a "hash rocket" style.

Rails Console Tricks (screencast) - A screencast by Ryan Bates on the Rails console (a cousin of IRB) featuring a ton of useful tips, some of which are useful to IRB users generally.

Wirble: Tab-Completion and Syntax Coloring for irb - Wirble (homepage) is a Ruby library that adds a number of features to IRB. Of particular interest is its addition of syntax coloring. Install the wirble gem, add a few lines to your .irbrc file, and you get colored results in the data structures coming back from your IRB commands.

IRB documentation from the old Pickaxe - A lengthy page about IRB from the first edition of Programming Ruby (the Pickaxe). Not very up to date but sufficient for Ruby 1.8. Covers command line options, configuration files, and some of the special variables are commands available when running IRB.

Try Ruby - Not got Ruby installed or want to play in an IRB that's not your own? whytheluckystiff's Try Ruby is a great way to play with IRB through a Web browser. It includes an interactive tutorial, too.
 

If you know some interesting things about IRB let me know and yes your comments. :)

No comments:

Post a Comment