Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Improvements for Ruby's IRB

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
screenshots
.gitignore
CHANGELOG
LICENSE
README.rdoc
Rakefile
VERSION
every_day_irb.gemspec
irbtools.gemspec

README.rdoc

irbtools

The irbtools gem is a meta gem that installs handy and useful irb gems and provides an appealing ready-to-use irb configuration. It has a modular structure and supports multiple library-loading mechanisms, e.g. via autoload or threads.

Setup

gem install irbtools
  • On Linux, you need xclip or xsel to use the clipboard: sudo apt-get install xclip

  • On Windows, you need ansicon to enjoy all the colors

  • On MacOS, you need growl, to use the g gem.

Usage

To use irbtools, put the following in your ~/.irbrc file (this file is loaded every time you start irb):

require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
require 'irbtools'

If the file does not exist, just create a new one. See further below on how to customize loaded libraries.

Rails notes

To integrate irbtools into a rails console, you will have to add irbtools to your Gemfile in this way: (or there will be some bundler double require issues..)

gem 'irbtools', :require => false

You can put Rails specific configuration in a ~/.railsrc file that only gets loaded in Rails environments.

See this blog post for some Rails goodies.

This is irbtools “light”

When installing irbtools, some gems won't be installed to keep windows support, e.g. better auto-completion or the looksee gem. These are packaged in the irbtools-more gem. To use them, you need to change your .irbrc to:

require 'irbtools/configure'
Irbtools.add_package :more
Irbtools.start

In that case, the Gemfile line looks like this:

gem 'irbtools-more', :require => false

Included gems and libraries

See rbjl.net/40-irbtools-release-the-power-of-irb or read the commented source files to get some examples of what you can do with irbtools.

wirb

Colorizes Ruby objects (used for the results)

paint

Provides easily to use terminal colors

hirb

Custom views for specific objects, e.g. tables for ActiveRecord

fancy_irb

Hash rockets for results and colorful error messages

every_day_irb

Contains helper methods that might be useful in every-day irb usage, see below for details

clipboard

Easy clipboard access

interactive_editor

Lets you open vim from within irb to hack something that gets loaded into the current session, also possible: yaml object editing

sketches

Another, more flexible “start editor and it gets loaded into your irb session” plugin

zucker

Nice debug printing (q, o, c, Object#m, Object#d) and useful pseudo-constants (Info, OS, RubyVersion, RubyEngine)

ap

Nice debug printing commands (ap) [also possible: wp from wirb/wp]

coderay

Colorizes Ruby code (colorize, ray)

boson

“A command/task framework similar to rake and thor that opens your ruby universe to the commandline and irb.”

methodfinder

Interesting method finder (mf)

ori

Adds an Object#ri method

method_locator

Provides Object#method_lookup_path (improved version of Module#ancestors) and Object#methods_for (get this method from all ancestors)

method_source

Object#src can be shown for Ruby methods

bond

irbtools-more: Improves irb tab-completion

looksee

irbtools-more: Great load path inspector: Object#l (Extended version of Object#m), also provides the ability to Object#edit methods.

drx

irbtools-more: A tk object inspector, defines Object#see

fileutils (stdlib)

Includes file system utility methods: cd, pwd, ln_s, mv, rm, mkdir, touch, … ;)

Not included anymore

guessmethod

Automatically tries to corrects typos in method names

rvm_loader

RVM helpers

Irbtools methods

The following general helper methods are defined by every_day_irb (which belongs to irbtools)

ls

Returns an array with the directory's content

cat

Shortcut for File.read

rq

Shortcut for require library.to_s (allows concise syntax like rq:mathn)

ld

Shortcut for load library.to_s + '.rb'

rrq/rerequire

Little hack for rerequiring a library (it's really hack and not reliable, but works in most cases)

reset!

Restarts irb

clear

Clears your irb terminal (system "clear")

session_history

Returns all issued commands as string

dbg

Shortcut for debugger that also requires 'ruby-debug' if needed

Irbtools also defines some more helpers in combination with the loaded gems:

cd

Improves the cd that is already provided by FileUtils (try cd '-')

rv

Displays RubyVersion (zucker)

re

Displays RubyEngine (zucker)

colorize

Syntax highlights a ruby string using CodeRay

ray

Syntax highlights a ruby file using CodeRay

copy

Shortcut for Clipboard.copy

paste

Shortcut for Clipboard.paste

copy_input

Copies the session_history to the clipboard

copy_output

Copies this session's results to the clipboard

mf

Shortcut for using the methodfinder

These are the custom public Object methods renamed/patched for some gems

ri

Patching the ri provided by ori to also allow default ri syntax on toplevel

src

Shortcut for displaying the method source using method_source and coderay

l/ll

Alternative method name to trigger the looksee gem (irbtools-more)

How to load more or less libraries

It's possible to modify, which libraries should get loaded:

# don't require 'irbtools', but:
require 'irbtools/configure'
# here you can modify the libraries using the methods below
Irbtools.start

If you don't want to load the default set of irbtools gems, you will have to use require 'irbtools/minimal' instead of configure.

You have the following methods:

  • Irbtools.add_library(lib, options_hash, &block)

  • Irbtools.remove_library(lib)

The options_hash defines the way in which Irbtools loads the library. Following options are possible

(no options)/:start

The library is required on startup before doing anything else (before displaying the prompt)

:thread => identifier

After loading everything else, the library is required in a thread (while continuing loading). You can choose any identifier, but if you take the same one for multiple libraries, they will be loaded in the same thread (in the order that you define)

:late => true

The library is required just before showing the prompt (note: loading threads might still be in process)

:late_thread => identifier

Same as :thread, but after loading late libraries.

:sub_session => true

The library is loaded every time a sub-session starts (using IRB.conf[:IRB_RC]). In ripl, ripl-after_rc is used.

:autoload => :Constant

Use Ruby's autoload feature. It loads the library as soon as the constant is encountered.

You can also apply a block that gets executed after the library is loaded (except for autoload, the code will executed on startup in this case). You can also just add callback block by using the Irbtools.add_library_callback or the Irbtools.replace_library_callback method.

When adding a new library, you should firstly consider some way to load it via :autoload. If not possible, try loading via thread. If that is not possible either, fallback to the default loading.

Troubleshooting: Unicode caused Wrong display widths?

When using double-width unicode chars, you need to paste the following snippet to your .irbrc.

Irbtools.replace_library_callback :fancy_irb do
  FancyIrb.start :east_asian_width => true
end

This setting is deactivated by default because of performance issues.

Hint: Faster start-up

You can get an about a second faster start-up time by changing the loading methods for wirb and fancy_irb to :thread (drawback: the hash rocket will not be used for the first result):

require 'irbtools/configure'
Irbtools.remove_library :paint
Irbtools.remove_library :fancy_irb
Irbtools.add_library :paint, :late => true do Wirb.load_schema :classic_paint if defined? Wirb end
Irbtools.add_library :fancy_irb, :thread => -1 do FancyIrb.start end
Irbtools.start

Welcome message

The welcome message can be customized with Irbtools.welcome_message=

Packages

There are irbtools extension packages, which can be modified via:

  • Irbtools.add_package(pkg)

  • Irbtools.remove_package(pkg)

These packages add/modify the libraries to be loaded. For an example, see irbtools-more.

Copyright

Copyright © 2010-2012 Jan Lelis, rbjl.net, released under the MIT license.

J-_-L

Something went wrong with that request. Please try again.