The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Stupid IRB Tricks

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Christopher Cyll

Posts: 49
Nickname: topher
Registered: Jan, 2006

Topher Cyll is Rubyist and writer in Portland, Oregon.
Stupid IRB Tricks Posted: Feb 9, 2012 10:27 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Christopher Cyll.
Original Post: Stupid IRB Tricks
Feed Title: Topher Cyll
Feed URL: http://feeds.feedburner.com/cyll
Feed Description: I'm not too worried about it. Ruby and programming languages.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Christopher Cyll
Latest Posts From Topher Cyll

Advertisement

This post reflects some tricks I sent out in a mail to PDX.rb and some others I posted on my Intel internal Ruby blog. There’s nothing terribly novel here, but if you haven’t stumbled on these yet, they might save you some time.

Your .irbrc file gives you a lot of control over what your IRB looks like each time it starts. Here’s what my .irbrc file looks like:

require 'irb/completion'
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]

class Object
  def mymethods
    (self.methods - self.class.superclass.instance_methods).sort
  end
end

The first two lines turn on tab completion. If you don’t have this on already, turn it on now! It only works when IRB can figure out the type of expressions, but it helps make the interpreter more friendly. Type []. and hit tab to see the array methods tab complete.

The second chunk sets up an useful introspection function that Ben and I came up with. It allows me to type foo.mymethods and get only the methods that are defined for foo, but not the methods defined in its superclass, which I find is often what I want (and sorted!). This is important because sometimes Ruby’s humane interface means the number of methods can be a little overwhelming.

Oh, and one other tip! If you’re doing interactive shell scripting in irb, you’ll often get into situations where the huge list of files you’re copying, or text-replacing or whatever is printing after every command since most Ruby commands return values. Waiting for hundreds of lines to print after each command can start to drive you nuts. Thankfully, you can shut off this echoing behavior in irb by typing:

conf.echo = nil

Those are all the tricks I can think of, but there must be more out there…

Read: Stupid IRB Tricks

Topic: Stupid IRB Tricks Previous Topic   Next Topic Topic: My list of JBoss Drools resources...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use