Tuesday, May 01, 2012

irb tricks

1. touch ~/.irbrc
2. Edit the .irbrc and add the following code:


require 'pp'
require 'rubygems'

class Object
  def ls
    %x{ls}.split("\n")
  end
 
  def pwd
    Dir.pwd
  end
 
  def cd(dir)
    Dir.chdir(dir)
    pwd
  end
end

alias p pp

3. Now whenever you open an irb session you can now list the directory contents by doing ls, print working directory by pwd and change directory by doing cd "directory-name".